heap sorting is an algorithm with excellent performance. generally, the sorting effect is achieved through the data structure-Max heap, the general steps are: heap building-sorting, heap building and sorting are mixed to maintain the stability of the heap. Priority Queues also use data structure heaps. The main C language algorithms are as follows:
# Include <stdio. h> # include <limits. h> // record the maximum heap length unsigned int heap_size = 0; // The subscript starts from 0. // find the subscript unsigned int parent (unsigned int index) of the parent node) {return (index-1)/2;} // evaluate the subscript unsigned int lchild (unsigned int index) of the Left son node {return 2 * index + 1 ;} // calculate the subscript unsigned int rchild (unsigned int index) {return 2 * index + 2;} // maintain the maximum heap order void max_heapify (int *, unsigned int I) {unsigned int L, R, largest; inttemp; Largest = I; L = Lchild (I); r = rchild (I); If (L