Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions partialsort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//Sorting Algorithm using STL
//Partial Sort Method

#include <bits/stdc++. h>
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 */
}