Advertisement
Guest User

sortiranje

a guest
May 22nd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. int N;
  5. char (*a)[20] = new char [N][20];
  6.  
  7.  
  8.  
  9. void bubb_sort(int rijec)
  10. {
  11.     for (int j=0;j<strlen(a[rijec]);j++)
  12.     {
  13.  
  14.         for (int i=0; i<strlen(a[rijec])-1; i++)
  15.         {
  16.             if (a[rijec][i]>a[rijec][i+1])
  17.             {
  18.                 char pom=a[rijec][i+1];
  19.                 a[rijec][i+1]=a[rijec][i];
  20.                 a[rijec][i]=pom;
  21.             }
  22.            
  23.             /*cout<<"-------------"<<endl;
  24.             cout<<"i="<<i<<endl;
  25.             cout<<"i+1="<<i+1<<endl;
  26.             cout<<"-------------"<<endl;*/
  27.         }
  28.     }
  29. }
  30.  
  31.  
  32. int main()
  33. {
  34.     do
  35.     {
  36.         cin>>N;
  37.     }while(!(N<20));
  38.    
  39.     for(int i=0; i<N; i++)
  40.         cin>>a[i];
  41.    
  42.     for (int i=0; i<N; i++)
  43.         bubb_sort(i);
  44.    
  45.     for (int i=0; i<N; i++)
  46.         cout<<a[i]<<endl;
  47.        
  48.    
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement