Skip to content

Commit eecaaba

Browse files
authored
Update Heap Sort .cpp
updated the document
1 parent 713fade commit eecaaba

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

sorting/Heap Sort .cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
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+
121
#include<iostream>
222
using namespace std;
323
void heapify(int arr[], int n, int i){

0 commit comments

Comments
 (0)