File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ Heap sort is a sorting technique based on comparison based on binary heap data.
3
+ Similar to sorting, it finds the largest number first and then puts the largest number last.
4
+
5
+
6
+ This sorting algorithm uses a tree structure called the stack, where the stack is a kind of binary tree.
7
+ A binary decision tree in which the value of the root of a tree is less than or equal to the value of one of its roots is called a min-heap.
8
+ A decision binary tree is called maximum heap when the value of the root of a tree is greater than or equal to the value of one of its trees.
9
+ In this post, we'll learn more about C++ Stack Sorting.
10
+
11
+ Working of heap sort in C++
12
+ To sort any list into a logical order following steps are followed:-
13
+
14
+ Convert the list into a heap.
15
+ Now convert this heap into a max heap.
16
+ As the heap is converted to max heap largest element in the list is stored in the root of the heap, replace it with the last item of the heap.
17
+ Now delete this node and reduce the size of the heap by 1.
18
+ Follow these steps until the list is sorted.
19
+ */
20
+
1
21
#include < iostream>
2
22
using namespace std ;
3
23
void heapify (int arr[], int n, int i){
You can’t perform that action at this time.
0 commit comments