Skip to content

Instantly share code, notes, and snippets.

@godtaehee
Created April 5, 2019 03:06
Show Gist options
  • Save godtaehee/a4f6b806c391ba2af4c885bcb66b5377 to your computer and use it in GitHub Desktop.
Save godtaehee/a4f6b806c391ba2af4c885bcb66b5377 to your computer and use it in GitHub Desktop.
#Algorithm Sort
//
// Created by 김태희 on 2019-04-05.
//
#include <iostream>
using namespace std;
int main(){
int n;
int loc;
int Item;
cin >> n;
int arr[n];
for(int i = 0; i < n; i++){
cin >> arr[i];
}
for(int i = 1; i < n; i++){
loc = i-1;
Item = arr[i];
while(loc >= 0 && Item < arr[loc]){
arr[loc + 1] = arr[loc];
loc--;
}
arr[loc+1] = Item;
}
for(int i = 0; i < n; i++){
cout << arr[i] << ' ';
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment