Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ISF_17/1. Robert Kropa, Raimond Silobrit, Pavel Trostianko
- //Bubble Sort
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- int amount, ats, tmp,n[1000];
- string failas="test.txt", rez="rez.txt";
- void Didejimo()
- {
- for(int q=0;q<amount;q++)
- {
- for(int d=0;d<amount-1;d++)
- {
- if(n[d]>n[d+1])
- {
- tmp = n[d];
- n[d] = n[d+1];
- n[d+1] = tmp;
- }
- }
- }
- ofstream fen(rez.c_str());
- for(int ii=0;ii<amount;ii++)
- {
- fen << n[ii] << endl;
- }
- }
- void Mazejimo()
- {
- for(int q=0;q<amount;q++)
- {
- for(int d=0;d<amount-1;d++)
- {
- if(n[d]<n[d+1])
- {
- tmp = n[d+1];
- n[d+1] = n[d];
- n[d] = tmp;
- }
- }
- }
- ofstream fen(rez.c_str());
- for(int ii=0;ii<amount;ii++)
- {
- fen << n[ii] << endl;
- }
- }
- int main()
- {
- cout << "ISf-17/1 Bubble 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement