c++ - Use of unique on STL vector with a structure -


In a programming function, I am trying to ensure that only a unique item contains unique items in primitive types With, the operation is as simple as:

  vector & lt; Int & gt; Lala; Lala.push_back (1); Lala.push_back (99); Lala.push_back (3); Lala.push_back (99); Sort (lala.bjin (), lala.nd ()); // Lala: 1, 3, 99, 99 Lala.Raze (Unique (Lala.bizin), Lala.nd ()), Lala.And ()); // Lala: 1, 3, 99  

However, the problem is that I am not using int. But:

  Type -File {int x; Int y; Int maxX; Integer maximum; Integer width Inti height; Int id; } Rectangle; Bool SameRect (Rake first, next second) {return first.x == second.x & amp; Amp; First.y == sec. Y & amp; Amp; First. With == seconds.With & amp; Amp; first. Heights == seconds. Heights & amp; Amp; First.mxx == seconds.Maxx & amp; First. MaxY == seconds. MaxY; } // ... vector & lt; Rect & gt; Lala; // ... sort (lala.bjin (), lala.and ()); Lala.Raze (Unique (Lala.bjin (), Lala.and (), Equirect), Lala.nd ()); // ...  

does not really work, what did I do?

Edit:

With the advice of Sth, I implemented two pseudo-std for std :: sort ():

  bool sort (Constant Rect & amp; First, Constant & amp; Seconds) {if (first. X  second.x) false return; If (first .a & lt; second.y) returns the truth; If (first .Y> second.y) is false; If (first.maxx  second; return) returns wrong; If (previously .text; second.height) return true; If (first.height> second.height) returned incorrectly; If (first.id  second.id) false return; return false; }  

But I think it has a similar effect:

  bool sortrect (const rect and first, const rect and second) {return first. X & lt; Second.x; }  

If SGI documents do not come up anything. Small, simple sorting verdict should also work. My test has confirmed this (though I have not tried all possible combinations).

You also have to define a comparative task that is sort () Should be used so that the rigs can be sorted. This one should be applied so that the same elements in the vector end next to each other.

If the vector is not sorted, then unique () will not get duplicate elements without order


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -