排序(sort)
语法:
1 2 |
void sort(); void sort( Comp compfunction ); |
sort()函数为链表排序,默认是升序。如果指定compfunction的话,就采用指定函数来判定两个元素的大小。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
源代码 /** * @brief Sort the elements. * * Sorts the elements of this list in NlogN time. Equivalent * elements remain in list order. */ void sort(); /** * @brief Sort the elements according to comparison function. * * Sorts the elements of this list in NlogN time. Equivalent * elements remain in list order. */ template<typename _StrictWeakOrdering> void sort(_StrictWeakOrdering); |
测试代码
测试结果
19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0