Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #include <time.h>
- using namespace std;
- int ile;
- clock_t start, stop;
- double czas;
- void sort_babelkowe(int *tab, int n)
- {
- for(int i=1; i<n; i++)
- {
- for(int j=n-1; j>=1; i--)
- {
- if(tab[j]<tab[j-1])
- {
- int bufor;
- bufor=tab[j-1];
- tab[j-1]=tab[j];
- tab[j]=bufor;
- }
- }
- }
- }
- int main()
- {
- cout<<"Porownanie czasow sortowania v.1"<<endl;
- cout<<"Ile losowych liczb w tablicy: ";
- cin>>ile;
- int *tablica;
- tablica = new int [ile];
- srand(time(NULL));
- for(int i=0; i<ile; i++)
- {
- tablica[i] = rand()%100000+1;
- }
- cout<<"Przed posortowaniem: "<<endl;
- for(int i=0; i<ile; i++)
- {
- cout<<tablica[i]<<" ";
- }
- cout<<"Sortuje Prosze czekac"<<endl;
- start = clock();
- sort_babelkowe(tablica, ile);
- stop = clock();
- czas = (double)(stop-start) / CLOCKS_PER_SEC;
- cout<<"Po posortowaniu: ";
- for(int i=0; i<ile; i++)
- {
- cout<<tablica[i]<<" ";
- }
- cout<<endl<<"Czas sortowania babelkowego to: "<<czas<<" s"<<endl;
- delete [] tablica;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement