Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ISF_17/1. Robert Kropa, Raimond Silobrit, Pavel Trostianko
- //Selection Sort
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <stdio.h>
- using namespace std;
- int amount, ats, tmp,n[1000];
- string failas="test.txt", rez="rez.txt";
- void swap(int *xp, int *yp)
- {
- int temp = *xp;
- *xp = *yp;
- *yp = temp;
- }
- void Didejimo()
- {
- int i,j, min_idx;
- for (i = 0; i < amount-1; i++)
- {
- min_idx = i;
- for (j = i+1; j < amount; j++)
- if (n[j] < n[min_idx])
- min_idx = j;
- swap(&n[min_idx], &n[i]);
- }
- ofstream fen(rez.c_str());
- for(int ii=0;ii<amount;ii++)
- {
- fen << n[ii] << endl;
- }
- }
- void Mazejimo()
- {
- int i,j, min_idx;
- for (i = 0; i < amount-1; i++)
- {
- min_idx = i;
- for (j = i+1; j < amount; j++)
- if (n[j] > n[min_idx])
- min_idx = j;
- swap(&n[min_idx], &n[i]);
- }
- ofstream fen(rez.c_str());
- for(int ii=0;ii<amount;ii++)
- {
- fen << n[ii] << endl;
- }
- }
- int main()
- {
- cout << "ISf-17/1 Selection Sort. Robert Kropa, Raimond Silobrit, Pavel Trostianko." << endl;
- ifstream fin(failas.c_str());
- fin >> amount;
- for(int i=0;i<amount;i++)
- {
- fin >> n[i];
- }
- cout << "Iveskite 0 - jeigu norite isvesti elementus didejimo tvarka, 1 - jeigu mazejimo." << endl;
- cin >> ats;
- if(ats==0){Didejimo();}
- else if(ats==1){Mazejimo();}
- else{cout<<"Error!"<<endl;}
- return 0;
- }
Add Comment
Please, Sign In to add comment