Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int h[10],n;
- void heapbottom(int h[],int n)
- {
- int i,j;
- for (i=n/2;i>=1;i--)
- {
- int k=i;
- int v=h[k];
- bool heap=false;
- while(!heap&&2*k<=n)
- {
- cout<<"\n i value is :"<<i;
- j=2*k;
- if(j<n)//there sre 2 children
- {
- if(h[j]<h[j+1])
- j++;
- }
- if(v>=h[j])
- heap=true;
- else
- {
- h[k]=h[j];
- k=j;
- }
- h[k]=v;
- }//end of while
- }
- cout<<"\n HEAP GENERATED \n";
- for(int i=0;i<n;i++)
- cout<<"\n ELEMENT IS:"<<h[i];
- }
- int main()
- {
- cout<<"\n Enter the maximum number of array elements \n";
- cin>>n;
- cout<<"\n Enter the array to perform heap sort \n";
- for(int i=0;i<n;i++)
- cin>>h[i];
- heapbottom(h,n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement