Advertisement
Guest User

sort_głu i sort_bąb

a guest
May 19th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <cmath>
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cstdlib>
  5. #include <time.h>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int N;
  11.  
  12. int main()
  13. {
  14.  
  15. cout<<"Wprowadz ilosc liczb do tablicy: ";
  16. cin>>N;
  17.  
  18. int d[N],i;
  19.  
  20. srand((unsigned)time(NULL));
  21.  
  22. cout << "Przed sortowaniem:\n\n";
  23. for(i = 0; i < N; i++) d[i] = rand() % 100;
  24. for(i = 0; i < N; i++) cout << setw(4) << d[i];
  25. cout << endl;
  26.  
  27. i = 0;
  28. do
  29. {
  30. if(d[i] > d[i+1])
  31. {
  32. swap(d[i], d[i+1]);
  33. i = 0;
  34. continue;
  35. }
  36. i++;
  37. } while(i < N-1);
  38.  
  39. cout << "\nPo sortowaniu:\n\n";
  40. for(i = 0; i < N; i++) cout << setw(4) << d[i];
  41. cout << endl;
  42. return 0;
  43. }
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50. #include <iostream>
  51.  
  52. using namespace std;
  53. int t[5],i=0;
  54.  
  55. int main()
  56. {
  57. cout<<"SORTOWANIE BABELKOWE"<<endl;
  58.  
  59. do{
  60. cout<<"wpisz "<<i+1<<" liczbe:";
  61. cin>>t[i];
  62. i++;
  63. }while(i<5);
  64.  
  65. cout<<endl<<"wpisales takie liczby: ";
  66.  
  67. for(i=0; i<5; i++){
  68. cout<<t[i]<<" ";
  69. }
  70.  
  71. for(i=0; i<5; i++){
  72.  
  73. for(int a=0; a<4; a++){
  74.  
  75. if(t[a]>t[a+1]){
  76. swap(t[a],t[a+1]);
  77. }
  78. }
  79. }
  80.  
  81. cout<<endl<<"posortowane liczby: ";
  82.  
  83. for(i=0; i<5; i++){
  84. cout<<t[i]<<" ";
  85. }
  86.  
  87. return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement