Bubble and select sort

xiaoxiao2021-04-01  230

#include

#include

#include

//Bubble Sort

Void bubblesort (int * a, int LEN)

{

INT I, J, TEMP;

For (i = 0; i

{

For (j = 0; j

{

IF (a [j]> a [j 1])

{

Temp = a [j];

a [j] = a [j 1];

A [J 1] = TEMP;

}

}

}

}

// Select sort

Void SelectSort (int * a, int LEN)

{

INT I, J, TEMP, RESULT

For (i = 0; i

{

Temp = i;

For (j = i 1; j

{

IF (A [J]

{

TEMP = J;

}

}

IF (Temp! = i)

{

Result = a [i];

a [i] = a [TEMP];

A [Temp] = Result;

}

}

}

Void Print (Int * a, int LEN)

{

INT i = 0;

For (i = 0; i

{

Printf ("% d", a [i]);

}

Printf ("/ n");

}

int main ()

{

INT Value [10] = {38, 6, 14, 9, 7, 33, 67, 12, 34, 51};

Printf ("Bubblesort Result: / N");

Bubblesort (Value, 10);

Print (Value, 10);

Printf ("Bubblesort Result: / N");

SelectSort (Value, 10);

Print (Value, 10);

Return 0;

}


New Post(0)