Fourth, ordering algorithm
1. Quick sort:
Procedure Qsort (L, R: Integer);
Var i, J, MID: Integer;
Begin
I: = L; J: = R; MID: = a [(1) Div 2]; {{Defined the number of the current sequence in the middle position as an intermediate number
}
Repeat
While a [i] While a [J]> MID DO DO DEC (j); {在 半 半 小 数 数}}}}} If i <= j Then Begin {If you find a group of sorted targets, exchange them} SWAP (a [i], a [j]); INC (i); dec (j); {continuing to find} END; Until I> J; IF L I End; {sort} B. Insert Sort: Idea: Current a [1] .. a [i-1] has been ranked, now inserting a [i] to make A [1] .. a [i] is orderly. Procedure insert_sort; Var i, J: integer; Begin For i: = 2 to n Do Begin a [0]: = a [i]; J: = I-1; While a [0]
a [j 1]: = a [j]; J: = J-1; END; a [j 1]: = a [0]; END; End; {INSET_SORT} C. Select Sort: Procedure sort; Var i, j, k: integer; Begin For i: = 1 to N-1 DO For j: = i 1 to n DO IF A [I]> a [J] THEN SWAP (A [i], A [J]); END; D. Sprinkle Procedure bubble_sort; Var i, j, k: integer; Begin For i: = 1 to N-1 DO For J: = N DOWNTO I 1 DO IF A [J] END; E. Stack Sort: Procedure Sift (I, M: Integer); {Adjusting the subtree of I root into a pile, M is the total number of nodes} VAR K: Integer; Begin a [0]: = a [i]; k: = 2 * i; {The left child of the node i in the full binary tree is 2 * i, the right child is 2 * i 1} While K <= m Do Begin