Quick sort

xiaoxiao2021-04-01  224

// Quick sorting, the main thinking is to divide the records to be sorted into adjacent regions by sorting, // The keyword in one area is smaller than the keyword recorded in the other area, in respectively These two // areas are sorted to reach the entire sequence. The general situation is O (logn), the worst case is O (N)

#include

#define n 10

INT QSORTING (int * a, int start, int end) {

Int key = a [start];

While (start

While (Start = key) {

END -;

}

A [start] = a [end];

While (Start

START ;

}

a [end] = a [start];

}

a [start] = key;

Return Start;

}

Void Qsort (int * value, int start, int end) {

IF (NULL! = Value && Start

INT INDEX = QSORTING (Value, Start, End);

Qsort (Value, Start, INDEX-1);

Qsort (Value, INDEX 1, End);

}

}

INT main (int Argc, char ** argv)

{

INT A [N] = {1, 5, 2, 7, 9, 3, 6, 7, 10, 8};

QSORT (A, 0, N-1);

For (int i = 0; i

Printf (i == (N-1)? "% D": "% D,", A [i]);

}

Printf ("\ n");

Return 0;

}

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

New Post(0)