Heap sort forward--a brief introduction to the tree and the two fork tree
Special and commonly used tree--two-fork tree
Two special two-fork trees
How to store binary trees
A summary of two-fork tree
Heap Sort
Heap this thing ....
Heap sorting process:
Algorithm program for heap sequencing (the program needs to be understood):
defSift (Data,low,high):#Adjustment functioni = Low#the root of the tree is the father, the only leader herej = 2 * i + 1#the left child of the root is the son, this is the little leader.TMP = Data[i]#take the root out to make adjustments, lead here whileJ <= High:#High is actually the right son of the root (that is, the last son), if j= high means there is no right son, which means there must be a son in ifJ < High andDATA[J] < Data[j + 1]:#J < High represents a right son, Data[j] < Data[j + 1] indicating that the right son is bigger than his left son.J + = 1#This j becomes the right son, that is, if there is a greater value than J, then J becomes the greater value. ifTMP < DATA[J]:#If the leader can't do it,Data[i] = Data[j]#the small leader of the upperi = j#small leaders become big leadersj = 2 * i + 1#Small leaders turn into little leaders Else:#if the leader is competent Break #Well, then, stay.Data[i] = tmp#At the end I will definitely have a vacancy here, so no matter who the TEM is, it's going to occupy this vacancy.
NB Two group----heap sorting