From 9b29e52eb467d8aca73a626f82478a828babdd92 Mon Sep 17 00:00:00 2001 From: Harsha Kumar <49024565+HarshaKumar23@users.noreply.github.com> Date: Sat, 3 Oct 2020 04:31:11 +0530 Subject: [PATCH] Create partialsort.cpp --- partialsort.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 partialsort.cpp diff --git a/partialsort.cpp b/partialsort.cpp new file mode 100644 index 0000000..60ce198 --- /dev/null +++ b/partialsort.cpp @@ -0,0 +1,20 @@ +//Sorting Algorithm using STL +//Partial Sort Method + +#include +using namespace std; + +int main() +{ + int a[] = {9,8,7,6,5,4,3,2,1}; + + partial_sort(a, a+4, a+9); + /* now a is 1,2,3,4,9,8,7,6,5 */ + + int b[] = {1,5,6,2,4,8,9,3,7}; + + /* sorts b such that first 4 elements are the greatest elements + in the array and are in descending order */ + partial_sort(b, b+4, b+9); + /* now b is 9,8,7,6,1,2,4,3,5 */ +}