// Select Sort Method Selectionsort (int Arr [], int N) template
Void SelectionSort (T Arr [], int N) {int smallindex; // The minimum element of the smallest element in the table INT Pass, J; // Used to scan the subscriber subscript T Temp; // Used to exchange table elements Temporary variables // passes range from 0 to n-2 for (Pass = 0; Pass
Void Deselsort (T Arr [], int N) {int smallindex, largeIndex; // The smallest and maximum elements in the table INT LEFTPASS = 0, Rightpass = N-1, I, J; // Used to left from the table And the subscript T Temp of the scanning sub-table; // Temporary variable for switching elements while (LeftPass <= Rightpass) {// From the left and right edges SMALLINDEX = LeftPass; LargeIndex = Rightpass; // J and i traversing the entire child table arr [leftpass] ~ arr [rightpass] for (i = leftpass 1; i
LEFTPASS; J - ARR [LARGEINDEX]) LARGEINDEX = J; if (LargeIndex! = Rightpass) {TEMP = arr [rightpass]; arr [rightpass] = arr [largeIndex]; arr [largeIndex ] = Temp;} // From two-headed shrink sub-table LeftPass ; RightPass ---;
INT Bubblesort (T Arr [], int N) {bool exchanged = false; // Whether to exchange INT I, J; // Used to traverse the subscriber subscript T TEMP; // Temporary variable for exchange elements / / Start traversal process, the following standard j constitutes a sub-table, a total of N-1 sub-table for (j = n-1; j> = 0; j--) // J, shrink from N-1 ~ 0, Composition sub table 0 ~ n-1, 0 ~ n-2, 0 ~ n-3..0 ~ 1 {Exchanged = false; for (i = 0; i
Arr [i 1]) {TEMP = Arr [I]; Arr [i] = arr [i 1]; arr [i 1] = Temp; Exchanged = true;}}} (! Exchanged) Return NJ- 1; // If there is no exchange in a traversal, it is said that it has been // sorted, interrupt traversal process} return n-1-j;} // bubbling method Sorting general algorithm function bubblesortex () Implementation Template
INT Bubblesortex (T Arr [], INT N) {INT I, Pass; // Used to traverse the subscriber subscript T TEMP; // Temporary variable // start traversal process, the following standard J Table, a total of N-1 sub-table for (Pass = 0; Pass
Arr [i 1]) {TEMP = Arr [I]; Arr [i] = arr [i 1]; Arr [i 1] = Temp;}}} Return Pass;