View Single Post
Old Mar 26th, 2008, 6:46 AM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,435
Rep Power: 8 Ooble is on a distinguished road
Re: duplicate numbers in arrays

This sounds like a homework assignment to me, so I'm not sure if you'd be allowed to do this, but it would be really easy with sets. Sets are a type of data structure which are always ordered and can only store unique values, which sounds like what you're looking for. There's a set class in the STL.

To initialise a set:
set<int> list;
To put stuff in:
list.insert(n);
Don't worry about putting stuff in twice - it'll just ignore the duplicates.
And to get stuff out:
for (set<int>::iterator i = list.begin(); i != list.end(); i++) {
    cout << *i << " ";
}
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote