c++ - store array in vectors and sort the elements -
I have a large number of numbers in a number of three,
is there a way to store them The method is to sort the number of a vector in the form of a unit and for printing such that the combination on the first number is sorted, if it does, then duplicate, then sort them further on the basis of the second number is done.
More For expected output:
- 234 123 465
- 234 123 678
- 234 567 234
- 567 890 123 li>
You want basically two digit integers here, and then you want With custom comparator you can use std :: sort on it.
bool vector_cmp (const vector
& amp; v1; Const vector & lt; int & gt; and v2) {for (vector & lt; int & gt; :: size_type i = 0; i & lt; v1.size (); ++ i) {if (v1.at (i) & lt; v2.at (i)) true return; And if (v2.at (i) You can just type the previous line like this:
std :: sort (int2dVector.begin (), int2dVector.end ());
Already exit to compare the vectors.
operations , & lt; = And & gt; = Algorithm behaves like Lexifographical_Comparate, which is the sequence of elements in the operator & lt; Reflexively, stop at the first mismatch
Disclaimer: This is not completely unwanted and only proof of concept code.
Comments
Post a Comment