Advertisement
Guest User

Sort. babelkowe

a guest
Jun 30th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. int ile;
  8. clock_t start, stop;
  9. double czas;
  10.  
  11. void sort_babelkowe(int *tab, int n)
  12. {
  13.     for(int i=1; i<n; i++)
  14.     {
  15.         for(int j=n-1; j>=1; i--)
  16.         {
  17.             if(tab[j]<tab[j-1])
  18.             {
  19.                 int bufor;
  20.                 bufor=tab[j-1];
  21.                 tab[j-1]=tab[j];
  22.                 tab[j]=bufor;
  23.             }
  24.         }
  25.     }
  26. }
  27.  
  28. int main()
  29. {
  30.  
  31.     cout<<"Porownanie czasow sortowania v.1"<<endl;
  32.  
  33.     cout<<"Ile losowych liczb w tablicy: ";
  34.     cin>>ile;
  35.  
  36.     int *tablica;
  37.     tablica = new int [ile];
  38.  
  39.     srand(time(NULL));
  40.  
  41.     for(int i=0; i<ile; i++)
  42.     {
  43.         tablica[i] = rand()%100000+1;
  44.     }
  45.  
  46.     cout<<"Przed posortowaniem: "<<endl;
  47.     for(int i=0; i<ile; i++)
  48.     {
  49.         cout<<tablica[i]<<" ";
  50.     }
  51.  
  52.     cout<<"Sortuje Prosze czekac"<<endl;
  53.  
  54.     start = clock();
  55.  
  56.     sort_babelkowe(tablica, ile);
  57.  
  58.     stop = clock();
  59.  
  60.     czas = (double)(stop-start) / CLOCKS_PER_SEC;
  61.  
  62.     cout<<"Po posortowaniu: ";
  63.     for(int i=0; i<ile; i++)
  64.     {
  65.         cout<<tablica[i]<<" ";
  66.     }
  67.  
  68.     cout<<endl<<"Czas sortowania babelkowego to: "<<czas<<" s"<<endl;
  69.  
  70.     delete [] tablica;
  71.  
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement