Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- using namespace std;
- void sortuj1(int tab[],int x)
- {
- int i,j,pom;
- cout<<"tablica przed sortowaniem"<<endl;
- cout<<"---------------------------"<<endl;
- for(i=0;i<x;i++)
- {
- cout<<tab[i];
- }
- for(j=x;j>=0;j--)
- {
- for(i=x;i>=0;i--)
- {
- if(i+1<x)
- {
- if(tab[i]<tab[i+1])
- {pom=tab[i];
- tab[i]=tab[i+1];
- tab[i+1]=pom;}
- }
- }
- }
- cout<<endl<<"---------------------------"<<endl;
- cout<<"tablica po sortowaniu"<<endl;
- for(i=0;i<x;i++)
- {
- cout<<tab[i];
- }
- cout<<endl;
- cout<<"---------------------------"<<endl;
- }
- void sortuj2(int tab[], int x)
- {
- int i,z,pom,pom2;
- pom2=x;
- cout<<"tablica przed sortowaniem"<<endl;
- cout<<"---------------------------"<<endl;
- for(i=0;i<x;i++)
- {
- cout<<tab[i];
- }
- z=0;
- do
- {
- for(i=x-1;i>0;i--)
- {
- if(tab[i]>tab[i-1])
- {pom=tab[i];
- z=i;
- }
- }
- tab[z]=tab[x-1];
- tab[x-1]=pom;
- x--;
- }while(x>1);
- x=pom2;
- cout<<endl<<"---------------------------"<<endl;
- cout<<"tablica po sortowaniu"<<endl;
- for(i=0;i<x;i++)
- {
- cout<<tab[i];
- }
- cout<<endl;
- cout<<"---------------------------"<<endl;
- }
- void sortuj3(int tab[], int x)
- {
- cout<<"tablica przed sortowaniem"<<endl;
- cout<<"---------------------------"<<endl;
- int i,j,pom;
- for(i=0;i<x;i++)
- {
- cout<<tab[i];
- }
- for(int i=1; i<x ;++i)
- {
- int pom = tab[i];
- int j=i-1;
- while((j>=0) && (tab[j]<pom))
- {
- tab[j+1] = tab[j];
- --j;
- }
- tab[j+1] = pom;
- }
- cout<<endl<<"---------------------------"<<endl;
- cout<<"tablica po sortowaniu"<<endl;
- for(i=0;i<x;i++)
- {
- cout<<tab[i];
- }
- cout<<endl;
- cout<<"---------------------------"<<endl;
- }
- int main(int argc, char *argv[])
- {
- int j,i,x;
- int wtab = 5;
- int pom;
- cout<<"Podaj liczbe elementow tablicy"<<endl;
- cin>>x;
- int tab[x];
- for(i=0;i<x;i++)
- {cout<<"podaj element "<<i<<endl;
- cin>>tab[i];}
- //sortuj1(tab,x);
- //sortuj2(tab,x);
- sortuj3(tab,x);
- system("PAUSE");
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement