Created
October 9, 2016 03:08
-
-
Save shaunlgs/0ad5fb8d583de0553a50e79c64630ba0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <conio.h> | |
void BubbleSort(int [], int); | |
int main() | |
{ | |
int i,saiz=10, susun[10] = {24,64,10,5,6,31,15,20,56,34}; | |
printf("\n Data belum terisih :\n"); | |
for (i=0;i<10;i++) | |
printf("%3d",susun[i]); | |
BubbleSort(susun, saiz); | |
printf("\n Data telah terisih mengikut turutan menaik :\n"); | |
for (i=0;i<10;i++) | |
printf("%3d",susun[i]); | |
getch(); | |
return 0; | |
} | |
void BubbleSort(int data[], int listSize) | |
{ int pass, tempValue; | |
for (pass =1; pass<listSize; pass++ ) | |
{ | |
// moves the largest element to the | |
// end of the array | |
for (int x = 0; x < listSize - pass; x++) | |
//compare adjacent elements | |
if ( data[x]>data[x+1] ) | |
{ // swap elements | |
tempValue = data[x]; | |
data[x] = data[x+1]; | |
data[x+1] = tempValue; | |
} | |
} | |
} // end Bubble Sort |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment