Sorting structures. STL Part 13




sorting structures c ++, stl beginnersShown in the previous section various sorting - Flexible and beautiful mechanism for all occasions. That's just in practice, sort sequence almost never have a pure. This is all from the field of educational and demonstration tasks. In practice, the more often the problem is sorted quite voluminous data structures (even bulky in size, and according to the number of its fields). And sort (or resorting) they will have on the values ​​for the different fields of these same structures. But here come to the aid STL algorithms, especially when used in conjunction with the functors.

Let's see the typical model problem, which we've seen before - a description of the training group or faculty:

The program requests the field number data, on which sorting will be carried out (actually - comparison). If this number is entered, as a positive number, then sort by that field goes in ascending order. If the number is entered with a minus sign - the sort order is reversed:

sorting structures c ++, stl beginnerssorting structures c ++, stl beginners

Note, that the sorting algorithm does not care that sort: if the numeric data, the largest, and if lowercase, in order leksograficheskom.

Newsletter of programming:

Date
page
Sorting C ++ structures. STL Part 13
Rating
5
Olej

About Olej

practical experience about software development 40 years. Teacher Global Logic international software company. IBM Developer Works Permanent author of publications. Scientific editor of the computer literature publishing house "Symbol-Plus", St. Petersburg.

Leave a Reply

Place code in tags: <pre class="lang:c++ decode:true ">YOUR CODE</pre>