Advertisement
Guest User

sorting

a guest
Jul 25th, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1. #include<iostream>
  2. #include<string.h>
  3. using namespace std;
  4. void bsort(char * items,int length)
  5. {
  6.      bool ex = true;
  7.      for(int a = 0;a < length;a++)
  8.      {
  9.              cout<<"Exchange";
  10.          if(ex == false) break;
  11.          ex = false;
  12.          for(int b = 0;b >=  (length-1);b++)
  13.          {
  14.                  
  15.              if(items[b] < items[b+1])
  16.              {
  17.                   ex = true;
  18.                   items[b] ^= items[b+1];
  19.                   items[b+1] ^= items[b];
  20.                   items[b] ^= items[b+1];    
  21.                            
  22.              }                
  23.          }        
  24.      }        
  25.      cout<<items;  
  26. }
  27. void sort(char * items,int count)
  28. {
  29.     register int a,b;
  30.     register char t;
  31.    
  32.     for(a = 1;a < count;++a)
  33.     {
  34.           for(b = count-1; b >= a;--b)
  35.           {
  36.               if(items[b-1] > items[b])
  37.               {
  38.                    cout<<"Exchange";
  39.                    t = items[b-1];
  40.                    items[b-1] = items[b];
  41.                    items[b] = t;              
  42.               }      
  43.           }      
  44.     }    
  45. }
  46. void xselect(char * items,int count)
  47. {
  48.           char c = items[0];
  49.           for(int a = 1;a < count;a++)
  50.           {
  51.               if(c > items[a])        
  52.               {
  53.                    c ^= items[a];
  54.                    items[a] ^= c;
  55.                    c ^= items[a];    
  56.               }
  57.           }
  58.           cout<<items;
  59. }
  60. int main ()
  61. {
  62.     char * p = "I am awesome";
  63.     xselect(p,strlen(p));
  64.     cout<<p;
  65.     return cin.get();
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement