forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path3.cpp
More file actions
23 lines (20 loc) ยท 600 Bytes
/
3.cpp
File metadata and controls
23 lines (20 loc) ยท 600 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <bits/stdc++.h>
using namespace std;
int n = 10;
int arr[10] = {7, 5, 9, 0, 3, 1, 6, 2, 4, 8};
int main(void) {
for (int i = 1; i < n; i++) {
// ์ธ๋ฑ์ค i๋ถํฐ 1๊น์ง ๊ฐ์ํ๋ฉฐ ๋ฐ๋ณตํ๋ ๋ฌธ๋ฒ
for (int j = i; j > 0; j--) {
// ํ ์นธ์ฉ ์ผ์ชฝ์ผ๋ก ์ด๋
if (arr[j] < arr[j - 1]) {
swap(arr[j], arr[j - 1]);
}
// ์๊ธฐ๋ณด๋ค ์์ ๋ฐ์ดํฐ๋ฅผ ๋ง๋๋ฉด ๊ทธ ์์น์์ ๋ฉ์ถค
else break;
}
}
for(int i = 0; i < n; i++) {
cout << arr[i] << ' ';
}
}