Advertisement
rootuss

sortowanie babelkowe- tablica

Oct 23rd, 2016
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {   int l;
  7.  
  8.     cout<<"Podaj ilosc liczb do sortowania: ";
  9.     cin>>l;
  10.     cout << "podaj liczby" << endl;
  11.  
  12.     int *tablica= new int[l];
  13.     for (int i=0;i<l;i++)
  14.     {
  15.         cin>>tablica [i];
  16.     }
  17.  
  18. cout<<endl;
  19. cout<<"sortowanie rosnaco" <<endl;
  20.  
  21.     for (int i=0;i<l-1;i++)
  22.     {
  23.         for(int j=0;j<l-1;j++)
  24.             if(tablica[j]>tablica[j+1])
  25.         {
  26.             swap(tablica[j],tablica[j+1]);
  27.         }
  28.     }
  29.  
  30.     for (int i=0;i<l;i++)
  31.     {
  32.         cout<<tablica [i]<<endl;
  33.     }
  34.  
  35.  
  36. cout<<endl;
  37. cout<<"sortowanie malejaco" <<endl;
  38.  
  39.     for (int i=0;i<l-1;i++)
  40.     {
  41.         for(int j=0;j<l-1;j++)
  42.             if(tablica[j]<tablica[j+1])
  43.         {
  44.             swap(tablica[j],tablica[j+1]);
  45.         }
  46.     }
  47.  
  48.     for (int i=0;i<l;i++)
  49.     {
  50.         cout<<tablica [i]<<endl;
  51.     }
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement