array duplicates new to c++

Mar 30, 2014 at 10:41pm
hi can anyone help me with the implementation of is_not_duplicate please? need to enter numbers in an array, and as the array is read print it, as long as it is not a duplicate of a number already entered?
brand new to c++ so help would be appreciated

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main()
{  const int SIZE=50;
    int array[SIZE];
    int cnt = 0;  // Number of entries in the array
    int temp;

    cout << "Enter a list of numbers: ";
    for (int i=0; i<SIZE; i++)
    {    cin >> temp;
          if (is_not_duplicate (array, cnt, temp))
              array[cnt++] = temp;  // Not a duplicate, add to the array
    }
    getch();
    return 0;
} 
Mar 30, 2014 at 11:10pm
How about looping through the array and if you find the number return false, else return true.
Mar 31, 2014 at 11:45am
how would the implementation for that look?
Mar 31, 2014 at 2:51pm
you can you bsearch() function, which returns pointer to the first-found element in the array or NULL if there is no such element

http://www.cplusplus.com/reference/cstdlib/bsearch/?kw=bsearch
Topic archived. No new replies allowed.