Skip to content

Instantly share code, notes, and snippets.

@hassaanhameed786
Last active April 19, 2019 14:02
Show Gist options
  • Save hassaanhameed786/afc2193a3597a18bb8e5f16c3b83642a to your computer and use it in GitHub Desktop.
Save hassaanhameed786/afc2193a3597a18bb8e5f16c3b83642a to your computer and use it in GitHub Desktop.
MinumumHeap
#include<iostream>
using namespace std;
void Min_heap(int *array,int i, int n)
{
int j,temp;
temp =array[i];
j=2*i;
while(j<=n)
{
if(j<n && array[j+1] < array[j])
j = j+1;
if(array[j/2] = array[j]);
break;
if(temp >= array[j])
{
array[j/2] = array[j];
j = 2*j;
}
}
array[j/2] = temp;
return;
}
void Build_Min_Heap(int *array, int n)
{
for(int i = n/2; i>=1; i--)
Min_heap(array,i,n);
}
int main()
{
int n;
int i;
int x;
cout << "Enter Number of Elements of Array" <<endl;
cin >> n;
int array[22];
cout << "Enter Elements\n";
for(int i=1; i <= n; i++)
{
cin >> array[i];
}
Build_Min_Heap(array,n);
cout << "Minimum Heap\n";
for(int i =1; i <= n; i++)
{
cout << array[i] << endl;
}
}
@hassaanhameed786
Copy link
Author

A Minimum Heap is a Binary tree in which data contained in each node is less than the data in that node's children
Minimum Heap implemented using Array

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment