UNKNOWN //************************************** // Name: Min Heap // Description:This code is creating a min heap and implementing it using array. // By: Sunny2984 // // // Inputs:None // // Returns:None // //Assumes:None // //Side Effects:None //This code is copyrighted and has limited warranties. //Please see http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.13864/lngWId.3/qx/vb/scripts/ShowCode.htm //for details. //************************************** #include<conio.h> #include<iostream.h> void main() { clrscr(); int heap[50],n,i,k,t,p,ch; cout<<"enter 1st element : "; cin>>heap[1]; n=1; while(1) { cout<<"Press 1 to insert a new node : "; cin>>ch; if(ch==1) { cout<<"Enter the element : "; n++; cin>>heap[n]; k=n; p=n/2; while(p>=1) { if(heap[p] < heap[k]) break; else { t=heap[p]; heap[p]=heap[k]; heap[k]=t; k=p; p=p/2; } } } else break; } for(i=1;i<=n;i++) cout<<"\t"<<heap[i]; getch(); }