Skip to content

Commit b602447

Browse files
Merge pull request matthewsamuel95#802 from vmmc2/patch-2
Create SelectionSort.cpp
2 parents 2c7fd9c + e0b7276 commit b602447

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
void SelectionSort(int array[], int tam){
6+
int i, j;
7+
int menor, troca;
8+
for(i = 0; i < tam-1; i++){
9+
menor = i;
10+
for(j = i+1; j < tam; j++){
11+
if(array[j] < array[menor]){
12+
menor = j;
13+
}
14+
}
15+
if(i != menor){
16+
troca = array[i];
17+
array[i] = array[menor];
18+
array[menor] = troca;
19+
}
20+
}
21+
}
22+
23+
int main(){
24+
int vetor[10] = {5,6,8,3,4,2,1,0,9,7};
25+
SelectionSort(vetor, 10);
26+
printf("Your sorted array is:\n");
27+
for(int i = 0; i < 10; i++){
28+
printf("%d ", vetor[i]);
29+
}
30+
printf("\n");
31+
return 0;
32+
}

0 commit comments

Comments
 (0)