Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <time.h>
- #include <iomanip>
- #include <Windows.h>
- using namespace std;
- const int N = 10000;
- int main()
- {
- int d[N],i;
- DWORD t1,t2;
- cout<<"Sortowanie bombelkowe"<<endl<<endl;
- srand((unsigned)time(NULL));
- for(i=0; i<N;i++) d[i] = rand() % 100;
- cout<<"Przed sortowaniem"<<endl;
- for(i=0; i<N;i++) cout<<setw(4)<<d[i];
- cout<<endl;
- //algorytm sortowania
- t1 = GetTickCount();
- //____________________
- i = 0;
- do
- {
- if(d[i]>d[i+1])
- {
- swap(d[i],d[i+1]);
- i=0;
- continue;
- }
- i++;
- }while(i<N-1);
- //____________________
- t2 = GetTickCount() - t1;
- //koniec algorytmu
- cout<<"Po sortowaniu"<<endl;
- for(i=0; i<N;i++) cout<<setw(4)<<d[i];
- cout<<endl;
- cout<<"Czas wykonania "<<t2<<" milisekund"<<endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement