Advertisement
rengetsu

3ND_Algoritmai_BubbleSort

May 14th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. //ISF_17/1. Robert Kropa, Raimond Silobrit, Pavel Trostianko
  2. //Bubble Sort
  3.  
  4. #include <iostream>
  5. #include <fstream>
  6. #include <string>
  7.  
  8. using namespace std;
  9.  
  10. int amount, ats, tmp,n[1000];
  11. string failas="test.txt", rez="rez.txt";
  12.  
  13. void Didejimo()
  14. {
  15.     for(int q=0;q<amount;q++)
  16.     {
  17.         for(int d=0;d<amount-1;d++)
  18.         {
  19.             if(n[d]>n[d+1])
  20.             {
  21.                 tmp = n[d];
  22.                 n[d] = n[d+1];
  23.                 n[d+1] = tmp;
  24.             }
  25.         }
  26.     }
  27.     ofstream fen(rez.c_str());
  28.     for(int ii=0;ii<amount;ii++)
  29.     {
  30.         fen << n[ii] << endl;
  31.     }
  32. }
  33.  
  34. void Mazejimo()
  35. {
  36.     for(int q=0;q<amount;q++)
  37.     {
  38.         for(int d=0;d<amount-1;d++)
  39.         {
  40.             if(n[d]<n[d+1])
  41.             {
  42.                 tmp = n[d+1];
  43.                 n[d+1] = n[d];
  44.                 n[d] = tmp;
  45.             }
  46.         }
  47.     }
  48.     ofstream fen(rez.c_str());
  49.     for(int ii=0;ii<amount;ii++)
  50.     {
  51.         fen << n[ii] << endl;
  52.     }
  53. }
  54.  
  55. int main()
  56. {
  57.     cout << "ISf-17/1 Bubble Sort. Robert Kropa, Raimond Silobrit, Pavel Trostianko." << endl;
  58.     ifstream fin(failas.c_str());
  59.     fin >> amount;
  60.     for(int i=0;i<amount;i++)
  61.     {
  62.         fin >> n[i];
  63.     }
  64.     cout << "Iveskite 0 - jeigu norite isvesti elementus didejimo tvarka, 1 - jeigu mazejimo." << endl;
  65.     cin >> ats;
  66.     if(ats==0){Didejimo();}
  67.     else if(ats==1){Mazejimo();}
  68.     else{cout<<"Error!"<<endl;}
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement