Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. void sortuj1(int tab[],int x)
  7. {
  8. int i,j,pom;
  9.  
  10.  
  11. cout<<"tablica przed sortowaniem"<<endl;
  12. cout<<"---------------------------"<<endl;
  13.  
  14. for(i=0;i<x;i++)
  15. {
  16. cout<<tab[i];
  17. }
  18.  
  19.  
  20. for(j=x;j>=0;j--)
  21. {
  22. for(i=x;i>=0;i--)
  23. {
  24. if(i+1<x)
  25. {
  26. if(tab[i]<tab[i+1])
  27. {pom=tab[i];
  28. tab[i]=tab[i+1];
  29. tab[i+1]=pom;}
  30. }
  31. }
  32. }
  33.  
  34.  
  35. cout<<endl<<"---------------------------"<<endl;
  36. cout<<"tablica po sortowaniu"<<endl;
  37. for(i=0;i<x;i++)
  38. {
  39. cout<<tab[i];
  40. }
  41. cout<<endl;
  42.  
  43. cout<<"---------------------------"<<endl;
  44.  
  45.  
  46. }
  47.  
  48. void sortuj2(int tab[], int x)
  49. {
  50.  
  51. int i,z,pom,pom2;
  52. pom2=x;
  53. cout<<"tablica przed sortowaniem"<<endl;
  54. cout<<"---------------------------"<<endl;
  55.  
  56. for(i=0;i<x;i++)
  57. {
  58. cout<<tab[i];
  59. }
  60. z=0;
  61. do
  62. {
  63. for(i=x-1;i>0;i--)
  64. {
  65. if(tab[i]>tab[i-1])
  66. {pom=tab[i];
  67. z=i;
  68. }
  69. }
  70.  
  71. tab[z]=tab[x-1];
  72. tab[x-1]=pom;
  73. x--;
  74.  
  75.  
  76. }while(x>1);
  77. x=pom2;
  78. cout<<endl<<"---------------------------"<<endl;
  79. cout<<"tablica po sortowaniu"<<endl;
  80. for(i=0;i<x;i++)
  81. {
  82. cout<<tab[i];
  83. }
  84. cout<<endl;
  85.  
  86. cout<<"---------------------------"<<endl;
  87.  
  88.  
  89.  
  90. }
  91. void sortuj3(int tab[], int x)
  92. {
  93. cout<<"tablica przed sortowaniem"<<endl;
  94. cout<<"---------------------------"<<endl;
  95. int i,j,pom;
  96. for(i=0;i<x;i++)
  97. {
  98. cout<<tab[i];
  99. }
  100.  
  101.  
  102. for(int i=1; i<x ;++i)
  103. {
  104. int pom = tab[i];
  105. int j=i-1;
  106. while((j>=0) && (tab[j]<pom))
  107. {
  108. tab[j+1] = tab[j];
  109. --j;
  110. }
  111. tab[j+1] = pom;
  112. }
  113.  
  114.  
  115. cout<<endl<<"---------------------------"<<endl;
  116. cout<<"tablica po sortowaniu"<<endl;
  117. for(i=0;i<x;i++)
  118. {
  119. cout<<tab[i];
  120. }
  121. cout<<endl;
  122.  
  123. cout<<"---------------------------"<<endl;
  124.  
  125.  
  126.  
  127. }
  128.  
  129.  
  130.  
  131. int main(int argc, char *argv[])
  132. {
  133.  
  134. int j,i,x;
  135. int wtab = 5;
  136. int pom;
  137.  
  138. cout<<"Podaj liczbe elementow tablicy"<<endl;
  139. cin>>x;
  140. int tab[x];
  141. for(i=0;i<x;i++)
  142. {cout<<"podaj element "<<i<<endl;
  143. cin>>tab[i];}
  144.  
  145. //sortuj1(tab,x);
  146. //sortuj2(tab,x);
  147. sortuj3(tab,x);
  148. system("PAUSE");
  149. return EXIT_SUCCESS;
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement