A
avi
/* NumberGame.cpp : to find duplicates in a array */
#include "stdafx.h"
bool findDuplicates(int *, int);
typedef struct bst{
struct bst *left;
struct bst *right;
int val;
}bst;
bool insertv(bst*, int);
int _tmain(int argc, _TCHAR* argv[])
{
int iArrayhasd[]={1,2,3,2,14};
int size = sizeof iArrayhasd/sizeof iArrayhasd[0];
bool ans = findDuplicates(iArrayhasd, size);
return 0;
}
bool findDuplicates(int *arr, int size)
{
bool found = false;
bst *root;
for(int i=0;i<size;i++)
{
found = insertv(root,*(arr+i));
if (found)
{
printf("Duplocate value : %d", *(arr+i));
}
}
return found;
}
bool insertv(bst*root1, int cal)
/* I know that root1 is getting pass by value - what is the sol? */
{
if (root1 == NULL)
{
root1 = (bst*)malloc(sizeof(bst));
root1->left = NULL;
root1->right = NULL;
root1->val = cal;
return false;
}
if (root1->val == cal)
return true;
if (root1->val < cal)
return insertv(root1->right,cal);
else
return insertv(root1->left,cal);
}
#include "stdafx.h"
bool findDuplicates(int *, int);
typedef struct bst{
struct bst *left;
struct bst *right;
int val;
}bst;
bool insertv(bst*, int);
int _tmain(int argc, _TCHAR* argv[])
{
int iArrayhasd[]={1,2,3,2,14};
int size = sizeof iArrayhasd/sizeof iArrayhasd[0];
bool ans = findDuplicates(iArrayhasd, size);
return 0;
}
bool findDuplicates(int *arr, int size)
{
bool found = false;
bst *root;
for(int i=0;i<size;i++)
{
found = insertv(root,*(arr+i));
if (found)
{
printf("Duplocate value : %d", *(arr+i));
}
}
return found;
}
bool insertv(bst*root1, int cal)
/* I know that root1 is getting pass by value - what is the sol? */
{
if (root1 == NULL)
{
root1 = (bst*)malloc(sizeof(bst));
root1->left = NULL;
root1->right = NULL;
root1->val = cal;
return false;
}
if (root1->val == cal)
return true;
if (root1->val < cal)
return insertv(root1->right,cal);
else
return insertv(root1->left,cal);
}