Created
February 2, 2015 11:52
-
-
Save akerenyi/57b9174b42d45c89a0e5 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> | |
#define SIZE 10 | |
int main() { | |
// helper variables | |
int outer, inner, temp; | |
// array with SIZE | |
int numbers[SIZE]; | |
// Bubble sort | |
for(outer=0;outer<SIZE;outer++) | |
for(inner=outer+1;inner<SIZE;inner++) | |
{ | |
if( numbers[outer] > numbers[inner]) | |
{ | |
temp = numbers[inner]; | |
numbers[inner] = numbers[outer]; | |
numbers[outer] = temp; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment