1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Rep Power

    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?
  2. #2
  3. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Rep Power
    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.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

IMN logo majestic logo threadwatch logo seochat tools logo