Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSS.cpp
More file actions
Latest commit
46 lines (40 loc) · 1.12 KB
/
Copy pathSS.cpp
File metadata and controls
46 lines (40 loc) · 1.12 KB
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
#include<iostream>
intFI_GetSmallestIdx(int *IA_Arr, int I_Len, int I_Start = 0)
{
int I_SmallestIdx = I_Start;
for (size_t SzT_Idx = I_Start; SzT_Idx < I_Len; SzT_Idx++)
{
if (IA_Arr[SzT_Idx] < IA_Arr[I_SmallestIdx])
{
I_SmallestIdx = SzT_Idx;
}
}
return I_SmallestIdx;
}
voidF_SelectionSort(int* IA_Arr, int I_Len)
{
for (size_t SzT_Idx = 0; SzT_Idx < I_Len - 1; SzT_Idx++)
{
int I_MinIdx = FI_GetSmallestIdx(IA_Arr, I_Len, SzT_Idx + 1);
int I_Temp = IA_Arr[I_MinIdx];
IA_Arr[I_MinIdx] = IA_Arr[SzT_Idx];
IA_Arr[SzT_Idx] = I_Temp;
}
}
voidF_PrintArray(int *IA_Arr, int I_Len, bool B_Nl = false)
{
for (size_t SzT_Idx = 0; SzT_Idx < I_Len; SzT_Idx++) // Bruh
{
std::cout << IA_Arr[SzT_Idx] << (B_Nl ? "\n" : "");
}
std::cout << "\n";
}
intmain(int argc, charconst *argv[])
{
int IA_Arr[] = {156, 141, 35, 94, 88, 61, 111};
int I_Len = sizeof(IA_Arr) / sizeof(IA_Arr[0]);
F_PrintArray(IA_Arr, I_Len);
F_SelectionSort(IA_Arr, I_Len);
F_PrintArray(IA_Arr, I_Len);
return0;
}