Monday, May 24, 2010

C++ Programming check two vectors, same elements?

I'm having some serious issues with a programming question:





Write a predicate function





bool same_set(vector%26lt;int%26gt; a, vector%26lt;int%26gt; b)





that checks whether two vectors have the same elements in some order, ignoring multiplicities.





For example, the two vectors





1 4 9 16 9 7 4 9 11





and





11 11 7 9 16 4 1





would be considered identical.





It also states that I will probably need to use one or more helper functions for this programming.





If someone could help me solve this, even just some helpful pointers, it would be much appreciated. Thankyou.

C++ Programming check two vectors, same elements?
Because this is obviously a homework assignment I will just try and help with the general idea of how to solve this, instead of writing the code for you.





They basically want you to write a function that will check if the two vectors have all the same elements in them if you remove all of the duplicate numbers.





So how do you do this, well there are lots of ways.





The simplest is probably to sort them and then walk through the two vectors comparing them to one another as you skip over duplicate entries.





But there are plenty of other ways to accomplish the same thing.


No comments:

Post a Comment