sorting the iterators must support random access the sort algorithm does not guarantee that equal items retain their original order (if that is importantuse stable_sort instead of sortas an examplein std::sortv begin) end)std::sortv begin) end)greater)std::sortv begin) beginv endv begin )the first call sorts the entire containervin nondecreasing order the second call sorts the entire container in nonincreasing order the third call sorts the first half of the container in nondecreasing order the sorting algorithm used is generally quicksortwhich we describe in section in section we implement the simplest sorting algorithm using both our style of passing the array of comparable itemswhich yields the most straightforward codeand the interface supported by the stlwhich requires more code insertion sort one of the simplest sorting algorithms is the insertion sort the algorithm insertion sort consists of passes for pass through insertion sort ensures that the elements in positions through are in sorted order insertion sort makes use of the fact that elements in positions through are already known to be in sorted order figure shows sample array after each pass of insertion sort figure shows the general strategy in pass pwe move the element in position left until its correct place is found among the first + elements the code in figure implements this strategy lines to implement that data movement without the explicit use of swaps the element in position is moved to tmpand all larger elements (prior to position pare moved one spot to the right then tmp is moved to the correct spot this is the same technique that was used in the implementation of binary heaps original positions moved after after after after after figure insertion sort after each pass