Kassiow

Sortowanie bębelkowe tablic (od najm. do najw.)

Apr 25th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <climits>
  4. #include <stdlib.h>
  5. #include <ctime>
  6. using namespace std;
  7. void sort( int[]);
  8. int main()
  9. {
  10.     int a,b,tab[10];
  11.     cout << "podaj zakres" << endl;
  12.     srand(time(NULL));
  13.     cin>>a>>b;
  14.     for(int i=0;i<10;i++){
  15.     tab[i]=rand()%(b-a+1)+a;
  16.     }
  17.     sort(tab);
  18.     return 0;
  19. }
  20.  
  21. void sort( int tab[]){
  22.     for( int i=0;i<10;i++ )
  23.     {
  24.         for( int j=0;j<10-1;j++)
  25.         {
  26.             if( tab[j]>tab[j+1] )
  27.                  swap( tab[j] ,tab[j+1] );
  28.  
  29.         }
  30.  
  31.     }
  32.   for( int i=0;i<10;i++ ){
  33.     cout<<tab[i]<<" ";
  34.   }
  35.  
  36.  
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment