list::splice
Transfer elements from list to list.Transfers elements from x into the container, inserting them at position.
关键信息应该是Transfer和inserting them at position,也就是说会把一个链表的节点转移到另一个链表,并把转移过来的节点插入到指定的位置
The first version (1) transfers all the elements of x into the container.
The second version (2) transfers only the element pointed by i from x into the container.
The third version (3) transfers the range [first,last) from x into the container.
std::partition
Rearranges the elements from the range [first,last), in such a way that all the elements for which pred returns true precede all those for which it returns false.The iterator returned points to the first element of the second group.
关键信息是会根据pred的返回值进行rearranes,所有返回true的元素在所有返回false的元素前面,但相对顺序和调用前可能就不一样了。如果向保持相对顺序,可使用std::stable_partition
Possible output:
odd elements: 1 9 3 7 5
even elements: 6 4 8 2
QuickSort Algorithm
快速排序算法是初学编程就会接触到的基本算法,如下图所示
enter image description here
Using splice and partition to implemate the quicksort algorithm
领取专属 10元无门槛券
私享最新 技术干货