This is a variation of selection sort, it bring the largest pancake not yet sorted to the top with one flip; take it down to its final position with one more flip; and repeat this process for the remaining pancakes. The algorithm has been discussed in following wiki link: Pancake Sorting The algorithm is visually represented in following link: Pancake Sorting(Visualization) The idea of this sorting is similar to Selection Sort, here taking maximum items one by one and started placing those from last and at the same time reducing the vector size one by one. To place bigger items in order from last using flips two move to their respective positions. Here is the implementation using std::rotate() and std::reverse(). The output: