Skip to content

Instantly share code, notes, and snippets.

@tooshitaka
Created March 9, 2017 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tooshitaka/14532d31250bad311cb0fd295619e621 to your computer and use it in GitHub Desktop.
Save tooshitaka/14532d31250bad311cb0fd295619e621 to your computer and use it in GitHub Desktop.
#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