PCLP2/lab04/02.cpp
Fándly Gergő f5645fca66 chore: Lab04
2020-03-28 15:04:49 +02:00

48 lines
760 B
C++

#include <iostream>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <ctime>
using namespace std;
void sort_select(vector<int>* v){
for(int i=0; i<v->size()-1; i++){
int minpos = i;
int minval = v->at(i);
for(int j=i; j<v->size(); j++){
if(v->at(j) < minval){
minval = v->at(j);
minpos = j;
}
}
v->at(minpos) = v->at(i);
v->at(i) = minval;
}
}
int main(){
ios::sync_with_stdio(false);
srand(time(NULL));
vector<int> v(49);
iota(v.begin(), v.end(), 1);
vector<int> res;
for(int i=0; i<6; i++){
res.push_back(v[rand()%50]);
}
// sort
sort_select(&res);
cout<<"Elements in order: ";
for(vector<int>::iterator it = res.begin(); it < res.end(); it++){
cout<<*it<<" ";
}
cout<<endl;
return 0;
}