Comparing vectors

This is a discussion on Comparing vectors within the C++ Programming forums, part of the General Programming Boards category; How can I compare elements of two unordered vectors ? Where Code: vector A ( 1 2 3 4 5 ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Location
    Kansas City
    Posts
    76

    Comparing vectors

    How can I compare elements of two unordered vectors ?

    Where
    Code:
    vector A ( 1 2 3 4 5 }
    is the same as
    Code:
    vector B { 1 4 2 5 3 }
    .

    PS. What happened to all the old posts?

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,471
    sort them before comparing?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    >> PS. What happened to all the old posts?
    What happened

  4. #4
    Lean Mean Coding Machine KONI's Avatar
    Join Date
    Mar 2007
    Location
    Luxembourg, Europe
    Posts
    444
    If you don't want to sort them, you could use an array of piles or a map, then read the first vector, increment the counter for each element respectively, then read the second vector, decrement the counter for each element and see if all the counters are zero at the end.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Comparing vectors
    By Todd88 in forum C++ Programming
    Replies: 1
    Last Post: 09-25-2008, 02:48 PM
  2. Vectors
    By naseerhaider in forum C++ Programming
    Replies: 11
    Last Post: 05-09-2008, 08:21 AM
  3. How can i made vectors measuring program in DevC++
    By flame82 in forum C Programming
    Replies: 1
    Last Post: 05-07-2008, 02:05 PM
  4. How properly get data out of vectors of templates?
    By 6tr6tr in forum C++ Programming
    Replies: 4
    Last Post: 04-15-2008, 10:35 AM
  5. How to use Vector's in C++ !?!
    By IndioDoido in forum C++ Programming
    Replies: 3
    Last Post: 10-14-2007, 11:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21