Bubble algorithm

xiaoxiao2021-04-03  228

Alogrithm here is:

Void Bubble (INT * A, INT N)

{

INT count = 0;

INT NUM = 0;

Int temp;

INT I, J;

While (Num

{

For (i = 0; i

{

J = i 1;

IF (* (A I)> * (A J)))

{

TEMP = * (A I);

* (A I) = * (A J);

* (a j) = TEMP;

COUNT ;

}

}

IF (count == 0)

Break;

count = 0;

Num ;

}

FPRINTF (stderr, "% d / n", num);

}

This algorithm has been optimized, iterates less than N * (N-1) / 2, set a flag, and exit when there is no exchange.

Test a [8] = {35, 19, 63, 11, 73, 49, 40, 73}, ONLY Scan Three Times.

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

New Post(0)