Sorting Algorithm

xiaoxiao2021-03-06  144

#include

Void InsertSort (int Arr [], int LEN) {for (int i = 1; i = 0 && Temp < Arr [J]; J - {Arr [J 1] = Arr [J]} Arr [J 1] = Temp;}}

Void Binsertsort (int Arr [], int LEN) {for (int i = 1; i

While (Low <= high) {INT MID = (Low High) / 2; IF (Temp

For (int J = I-1; j> = high 1; j -) {arr [j 1] = arr [j];}

Arr [high 1] = TEMP;}}

Void SelectSort (int Arr [], int LEN) {for (int i = 0; i

Void Bubblesort (int Arr [], int LEN) {for (int i = len-1; i> 0; I -) {bool exchange = false; for (int J = 0; j Arr [J 1]) {INT TEMP = Arr [J]; Arr [J] = Arr [J 1]; Arr [J 1] = Temp; Exchanged = true;}}} (! Exchanged) {return;}}}

Void Quicksort (int Arr [], int low, int high {if (low> = high) {return;} int = low; int j = high; int spread = arr [i]; while (i I && arr [j] = pien) {j -;} arr [i] = arr [j];

While (i

Void main () {int Arr [] = {49, 38, 65, 97, 76, 13, 27, 49}; int Len = SizeOf (arr) / sizeof (Arr [0]); // Insertsort (Arr, Len); // binsertsort (Arr, Len); // SelectSort (Arr, Len); // bubblesort (arr, len); Quicksort (Arr, 0, LEN-1);

For (int i = 0; i

转载请注明原文地址:https://www.9cbs.com/read-127616.html

New Post(0)