Recommended Answers
Jump to Postqueue a; a.push(1); a.push(2); a.push(2); a.push(3);
to only have 3 elements, because 2 was added twice so the second time it is just ignored.
But you want this to have FIFO behaviour?
Why not create your own queue class, based on a deque for instance, which has …
Jump to PostWhy can't you use one of the generic algorithms to search your container for duplicates?
find or find_if spring to mind. each of these will return an iterator to the found element if it exists or end if no matching elements are found.
If your find returns end …
Jump to PostOr if you want terser code just put the find in the if too.
void push( const T& elem ) { if ( find( c.begin(), c.end(), elem )== c.end()) c.push_back(elem); }
ps. don't forget to #include <algorithm>
All 10 Replies
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.