Thread: Comparing vectors

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    sort them before comparing?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> PS. What happened to all the old posts?
    http://cboard.cprogramming.com/showthread.php?t=87796

  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