Debug So Long hhhhhhh
Words not much to say the sticker code
It is entirely possible to say that Exchange is written as a separate function to reduce the amount of code reuse;
#include <iostream> #include <cstdlib>using namespace std;void max_heapify (int *a,int i,int _size) {int l,r, largest; int temp; L = 2*i; R = 2*i+1; if (l<=_size && a[l]>a[i]) largest=l; else largest=i; if (r<=_size && a[r]>a[largest]) largest=r; if (largest!=i) {temp=a[i]; A[i]=a[largest]; A[largest]=temp; Max_heapify (a,largest,_size); }}void build_max_heap (int *a,int _size) {int i=0; for (i=_size/2;i>=1;i--) max_heapify (a,i,_size);} void Heap_sort (int *a,int length) {int _size=length; Build_max_heap (a,_size); int temp; for (int i=length;i>=2;i--) {temp=a[1]; A[1]=a[i]; A[i]=temp; _size--; Max_heapify (a,1,_size); }}int Main () {int a[6]; for (int i=0; i<6; i++) {cin>>a[i]; } heap_sort (a,5); for (int i=0; i<6; i++) {cout << a[i] << "; } return 0;}
233333333333333333333333333333 haha haha haha
Automated testing can be done with the rand () function of stdlib.h
Hum-hum ~~~~~~
Introduction to Algorithms (II.) heap sequencing