/* title: BubbleSort author: aeriqusyairi date: Jan25 2012 */ #include<stdio.h> #define SIZE 10 int main(){ int a[SIZE] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 }; int pass, i, hold; printf("Data items in original order\n"); /*output original array*/ for(i =0; i < SIZE; i++){ printf("%4d", a[i]); } /*bubble sort*/ for(pass = 1; pass < SIZE; pass++){ for(i = 0; i < SIZE - 1; i++){ if(a[i] > a[i+1]){ hold = a[i]; a[i] = a[i + 1]; a[i + 1] = hold; } } } printf("\nData items in ascending order\n"); for(i = 0; i < SIZE; i++){ printf("%4d", a[i]); } printf("\n"); system("pause"); return 0; }
My C Repository
C How to Program
Sweet thanks to my broski Yusuke Fiz for this Deitel book.
You light up my life dude.
Just another personal public repository.
Friday, March 16, 2012
Bubble Sort
Sorting an array with bubble sort.
Labels:
C,
Chapter 6: C Arrays
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment