Last active
August 11, 2018 17:57
-
-
Save sr6033/bade1a135c6152dc737b5bcf478c23ef to your computer and use it in GitHub Desktop.
Heap Sort using C++ STL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <bits/stdc++.h> | |
| using namespace std; | |
| int main() | |
| { | |
| int n; | |
| cin >> n; | |
| vector<int> arr(n); | |
| // Generating random numbers in a range of 0-100 | |
| for(int i = 0; i < n; i++) | |
| arr[i] = rand()%100+1; | |
| // Unsorted array | |
| for(int i = 0; i < n; i++) | |
| cout << arr[i] << " "; | |
| cout << endl; | |
| make_heap(arr.begin(), arr.end()); // Building the heap | |
| sort_heap(arr.begin(), arr.end()); // Heap sort | |
| // Sorted array | |
| for(int i = 0; i < n; i++) | |
| cout << arr[i] << " "; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment