asmodeus94

babelkoweIWybor

Feb 12th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdio>
  3. using namespace std;
  4. int tab[10],tab2[10],byl=0,byl2=0,przebieg=0,ify=0,przebieg2=0,ify2=0;;
  5. void wys(){
  6.      for(int i=0;i<10;i++){
  7.         cout<<"["<<tab[i]<<"] ";
  8. }
  9. if(byl==1){cout<<"Przebiegi: "<<przebieg<<"; ify: "<<ify;}
  10. cout<<endl;
  11.      for(int i=0;i<10;i++){
  12.         cout<<"["<<tab2[i]<<"] ";
  13. }
  14. if(byl2==1){cout<<"Przebiegi: "<<przebieg2<<"; ify: "<<ify2;}
  15. getchar();getchar();
  16. }
  17. void sortujB(){
  18. int j;
  19. byl=1;
  20. przebieg=0,ify=0;
  21.      for(int i=9;i>0;i--){
  22.               for(j=0;j<i;j++){
  23.               przebieg++;
  24.                  if(tab[j]>tab[j+1]){ify++;swap(tab[j],tab[j+1]);}
  25.               }
  26.      }
  27. }
  28. void los(){
  29. byl=0;byl2=0;
  30. srand(time(NULL));
  31. for(int i=0;i<10;i++){
  32.         tab[i]=rand()%10;tab2[i]=tab[i];
  33. }
  34. }
  35. void sortujWyb(){
  36. int i=0,poz=0,max;
  37. byl2=1;
  38. przebieg2=0,ify2=0;
  39. for(i=0;i<10;i++){
  40. max=tab2[i];
  41. poz=i;
  42.     for (int a=i;a<10;a++){
  43.         przebieg2++;
  44.            if (tab2[a]<max){
  45.            ify2++;
  46.            max=tab2[a];
  47.            poz=a;
  48.            swap(tab2[poz],tab2[i]);
  49.            }
  50.     }
  51. }
  52. }
  53. int main(){
  54. int wybor;          
  55. do{
  56. system("cls");
  57. cout<<"x=1 - wyswietl tablice\n";
  58. cout<<"x=2 - losuj\n";
  59. cout<<"x=3 - sortuj babelkowo\n";
  60. cout<<"x=4 - sortuj przez wybor\n";
  61. cout<<"x=5 - wyjscie\n";
  62. cout<<"Wybor: ";
  63. cin>>wybor;
  64. switch(wybor){
  65. case 1:{wys();break;}
  66. case 2:{los();break;}
  67. case 3:{sortujB();break;}
  68. case 4:{sortujWyb();break;}
  69. }}while(wybor!=5);            
  70. }
Advertisement
Add Comment
Please, Sign In to add comment