-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpp5weeks.cpp
54 lines (45 loc) · 926 Bytes
/
cpp5weeks.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
using namespace std;
#define NUMBER_TOTAL_SIZE 10
int number[NUMBER_TOTAL_SIZE] = {2, 4, 3, 5, 7, 6, 8, 9, 0};
void sorting() // 선택정렬
{
int min, idx;
int temp = 0;
for (int i = 0; i < NUMBER_TOTAL_SIZE; i++)
{
min = 9999;
for (int j = i; j < NUMBER_TOTAL_SIZE; j++)
{
if (min > number[j])
{
min = number[j];
idx = j;
}
}
temp = number[idx];
number[idx] = number[i];
number[i] = temp;
}
}
void add() // 숫자 삽입
{
for (int i = 0; i < NUMBER_TOTAL_SIZE; i++)
{
if (number[i] != i)
{
number[i] = i;
}
sorting();
}
}
int main()
{
sorting();
add();
sorting();
for (int i = 0; i < NUMBER_TOTAL_SIZE; i++)
{
printf("%d ", number[i]);
} // 결과 출력
}