Created
April 5, 2019 03:06
-
-
Save godtaehee/a4f6b806c391ba2af4c885bcb66b5377 to your computer and use it in GitHub Desktop.
#Algorithm Sort
This file contains hidden or 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
// | |
// 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