repl.it
@JimSkon/

SelectionSortExample

C++

No description

fork
loading
Files
  • main.cpp
main.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
#include <iostream>
using namespace std;
//const int n=5000;
const int max=1000;
void sort(int data[], int size);

void createData(int data[], int size);

int main() {
  
  int n;
  cout << "How many?";
  cin >> n;
  int score[n];

  createData(score,n);
  cout << "Created!" << endl;
  sort(score,n);
  for (int i=0; i<n; i++) {
    cout << score[i] << " ";
  }
  cout << endl;
}

void sort(int data[], int size) {

  for (int i=0; i<size-1 ; i++) {
    int min=i;
    for (int j=i+1; j<size; j++){
      if (data[min]>data[j]) {
        min = j;
      }
    }
    int t=data[min];
    data[min]=data[i];
    data[i]=t;

  }
}

void createData(int data[], int size){
  for (int i=0; i<size;i++) {
    int r = rand()%10000;
    data[i]=r;
  }
}