swap
语法:
1 |
void swap( list &lst ); |
swap()函数交换lst和现链表中的元素。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
源代码 /** * @brief Swaps data with another %list. * @param x A %list of the same element and allocator types. * * This exchanges the elements between two lists in constant * time. Note that the global std::swap() function is * specialized such that std::swap(l1,l2) will feed to this * function. */ void swap(list& __x) { _List_node_base::swap(this->_M_impl._M_node,__x._M_impl._M_node); } |
测试代码
测试结果
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
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