-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathArray_list.cpp
More file actions
42 lines (36 loc) · 777 Bytes
/
Array_list.cpp
File metadata and controls
42 lines (36 loc) · 777 Bytes
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
#include <iostream>
#include <iomanip>
#include <conio.h>
using namespace std;
void SelectionSort(int Array[],const int Size){
int i,j,smallest,temp;
for(i=0;i<Size;i++){
smallest=i;
for(j=i;j<Size;j++){
if(Array[smallest]>Array[j]){
smallest=j;
}
}
temp=Array[i];
Array[i]=Array[smallest];
Array[smallest]=temp;
}
for(int iii=0;iii<8;iii++)
cout<<setw(3)<<Array[smallest];
cout<<endl<<endl;
}
int main(){
int NumList[8] = {5, 34, 32, 25, 75, 42, 22, 2};
int temp;
cout<<"Data sebelum diurutkan: \n";
for (int d=0; d<8; d++){
cout<<setw(3)<<NumList[d];
}
cout<<"\n\n";
SelectionSort(NumList,8);
cout<<"Data setelah diurutkan:\n";
for (int iii=0; iii<8; iii++){
cout<<setw(3)<<NumList[iii]<<endl<<endl;
}
getche();
}