September 29th, 2003, 10:22 PM
comparing vectors for the same integer
I have vectors which contain integer values.
I want to check whether these vectors all contain some common integers.
I can take one by one and compare with the rest.
Is there any way, I can write an optimized code?
September 30th, 2003, 03:18 AM
Are your vectors sorted? If they are both the same, but one has an insert/delete, all will be 'different'. There are some sorting routines built into vectors, I think, but you still have to worry about having one extra or one less. As for optimization, using the bracket notation (myVect) should give you excellent performance. Keep in mind, though, for maximal speed you can't beat indexing into an int array. The vector does bounds checking on each access, not to mention all that pointer dereferencing, but all this is moot unless you have millions of elements to deal with.