Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- srand(time(NULL));
- int n;
- cout<<"ile liczb posortowac?"<<endl;
- cin>>n;
- int * a = new int[n];
- for(int k=0;k<n;k++)
- {
- a[k]=(rand()%100)+1;
- }
- int d=n/2,p,x=2;
- for(int j=0;j<n;j++)
- {
- cout<<j<<"-el :"<<a[j]<<endl;
- }
- cout<<endl;
- do
- {
- for(int i=d;i<n;i++)
- {
- if(a[i]<a[i-d])
- {
- p=a[i];
- a[i]=a[i-d];
- a[i-d]=p;
- while(i-(d*x)>=0)
- {
- if(a[i-(d*(x-1))]<a[i-(d*x)])
- {
- p=a[i-(d*(x-1))];
- a[i-(d*(x-1))]=a[i-(d*x)];
- a[i-(d*x)]=p;
- x++;
- }
- else
- {
- x=2;
- break;
- }
- }
- }
- }
- d=d/2;
- }while(d!=0);
- for(int j=0;j<n;j++)
- {
- cout<<j<<"-el :"<<a[j]<<endl;
- }
- delete [] a;
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement