Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prevent duplicates in a vector.sort(),Unique()

Status
Not open for further replies.

conor0callaghan

Programmer
Joined
Mar 18, 2002
Messages
20
Location
IE
I have a bit of a problem, if anyone can help I would be very gratefull!

I have a vector full of strings, this vector expands each time it receives a string, but I dont want it to take in duplicates, It is very important that the vector keeps the strings in the same order that they were received first.

vec_Files["this.h","that.h","These.h","those.h","that.h","those.h"]
i want
vec_Files["this.h","that.h","These.h","those.h"]

I'm thinking of using the sort() function and unique() but they wont keep the order!

Thanks
 
The answer to this is to have a second list of pointers that point into the vector array. Sort the pointer array and base things off of that.

Matt
 
P.S. You could use qsort and bsearch for this.

Matt
 
Thanks will look into that, I am currently looking at key map <map> what do you think of this?


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top