From 3c9b9a6d4be3516d6eedeea88bf58752102e13e1 Mon Sep 17 00:00:00 2001 From: Mohit Chandra Kukunoori Date: Fri, 26 Oct 2018 06:23:26 +0530 Subject: [PATCH] Created index.md for sort in stl-algorithms guide (#19546) * Created index.md for sort in stl-algorithms guide * Grammar, spelling fixes * Update index.md --- .../cplusplus/stl-algorithms/sort/index.md | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 guide/english/cplusplus/stl-algorithms/sort/index.md diff --git a/guide/english/cplusplus/stl-algorithms/sort/index.md b/guide/english/cplusplus/stl-algorithms/sort/index.md new file mode 100644 index 0000000000..4e9c27fe5f --- /dev/null +++ b/guide/english/cplusplus/stl-algorithms/sort/index.md @@ -0,0 +1,28 @@ +--- +title: STL Algorithms - Sorting +--- + +## std::sort + +This is an algorithm with O(n\*logn) time complexity that you can use to order the elements of a container from begin to end. + +The default ordering for numeric values is ascending and for string values it is lexicographical. The ordering of equal elements is not guaranteed to be preserved. + +It is a hybrid of Quick Sort and Heap Sort. + +Example: + +``` +vector v = {10,4,45,1}; //creates a vector +sort(v.begin(),v.end()); //Sorts the vector into{1,4,10,45} +``` + +``` +vector v = {10,4,45,1}; //creates a vector +sort(v.begin(),v.begin()+2); //Sorts only the first two elements {4,10,45,1} +``` + +### More Information: +1. [WikiPedia - Introsort](https://en.wikipedia.org/wiki/Introsort) +2. [CPP Reference](http://www.cplusplus.com/reference/algorithm/sort/) +3. [Youtube - CodeReport](https://www.youtube.com/watch?v=_dC6Pvk0awA)