Created
March 9, 2017 05:13
-
-
Save tooshitaka/14532d31250bad311cb0fd295619e621 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<iostream> | |
// Bubblesort | |
void bubblesort(int A[], int n) | |
{ | |
for (int i = 0; i < n; i++) { | |
for (int j = n - 1; j > 0; j--) { | |
if (A[j] < A[j - 1]) { | |
int tmp = A[j]; | |
A[j] = A[j - 1]; | |
A[j - 1] = tmp; | |
} | |
} | |
} | |
} | |
// MAIN FUNCTION | |
int main() | |
{ | |
// Input | |
int n; | |
int A[100]; | |
std::cin >> n; | |
for (int i = 0; i < n; i++) { | |
std::cin >> A[i]; | |
} | |
// Bubble sort | |
bubblesort(A, n); | |
for (int i = 0; i < n; i++) { | |
if (i) | |
std::cout << " "; | |
std::cout << A[i]; | |
} | |
std::cout << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment