diff --git a/Data Structures/Heap/CPP/max_heap.cpp b/Data Structures/Heap/CPP/max_heap.cpp new file mode 100644 index 00000000..a4db5453 --- /dev/null +++ b/Data Structures/Heap/CPP/max_heap.cpp @@ -0,0 +1,50 @@ + +//BUILDING MAX HEAP USING UPADJUSTMENT + +#include +using namespace std; +int main() +{ + int h[20]; + int n=0,largest=1; + int val,i=1,j=1,parent,temp; + int ans=0; + do + { + cout<<"\nEnter the node:"; + cin>>val; + + //UPADJUSTMENT: sorting while adding + + h[i]=val; + j=i; //current node + parent=j/2; //parent node of the current node + while(parent>=1) + { + if(h[parent]> ans; + }while(ans==1); + n=i-1; + h[0]=n; + + //Displaying the max heap. + + int k=1; + cout<<"The heap is as: "; + for(k=1;k<=n;k++) + { + cout<<" "<