MCPcopy Create free account
hub / github.com/E869120/math-algorithm-book / main

Function main

codes/cpp/Code_3_06_2.cpp:6–26  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4int N, A[200009];
5
6int main() {
7 // 入力
8 cin >> N;
9 for (int i = 1; i <= N; i++) cin >> A[i];
10
11 // 選択ソート
12 for (int i = 1; i <= N - 1; i++) {
13 int Min = i, Min_Value = A[i];
14 for (int j = i + 1; j <= N; j++) {
15 if (A[j] < Min_Value) {
16 Min = j; // Min は最小値のインデックス(1~N)
17 Min_Value = A[j]; // Min_Value は現時点での最小値
18 }
19 }
20 swap(A[i], A[Min]);
21 }
22
23 // 出力
24 for (int i = 1; i <= N; i++) cout << A[i] << endl;
25 return 0;
26}

Callers

nothing calls this directly

Calls 1

swapFunction · 0.85

Tested by

no test coverage detected