Created
December 5, 2013 14:36
-
-
Save olupotd/7806043 to your computer and use it in GitHub Desktop.
Bubble Sort in C
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> | |
int numb[8]; | |
int i, j, temp; | |
int main(int argc, char* argv[]) | |
{ | |
//populate the array | |
while(i < sizeof(numb)){ | |
numb[i] = i+2; | |
i++; | |
} | |
//sort the array with bubble sort | |
for(i=0;i<=5;i++) | |
{ | |
for(j=i+1;j<=sizeof(numb);j++) | |
{ | |
int temp; | |
if(numb[i] > numb[j]) | |
{ | |
temp = numb[i]; | |
numb[i] = numb[j]; | |
numb[j] = temp; | |
} | |
} | |
} | |
//print the results after the sorting | |
for(i=0;i<=sizeof(numb);i++) | |
{ | |
printf("%d\n", numb[i]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment