merge
语法:
1 2 |
void merge( list &lst ); void merge( list &lst, Comp compfunction ); |
merge()函数把自己和lst链表连接在一起,产生一个整齐排列的组合链表。如果指定compfunction,则将指定函数作为比较的依据。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
源代码 /** * @brief Merge sorted lists. * @param x Sorted list to merge. * * Assumes that both @a x and this list are sorted according to * operator<(). Merges elements of @a x into this list in * sorted order, leaving @a x empty when complete. Elements in * this list precede elements in @a x that are equal. */ void merge(list& __x); /** * @brief Merge sorted lists according to comparison function. * @param x Sorted list to merge. * @param StrictWeakOrdering Comparison function definining * sort order. * * Assumes that both @a x and this list are sorted according to * StrictWeakOrdering. Merges elements of @a x into this list * in sorted order, leaving @a x empty when complete. Elements * in this list precede elements in @a x that are equivalent * according to StrictWeakOrdering(). */ template<typename _StrictWeakOrdering> void merge(list&, _StrictWeakOrdering); |
测试代码
测试结果
8 8 8 8 9 8 7 6 5 4 3 2 1 0
8 8 8 8 9 8 7 6 5 5 5 5 4 3 2 1 0
《List链表merge()函数运用实例》上有1条评论
评论已关闭。