Monday, March 7, 2011

sorting

#include <iostream>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
using namespace std;
main()
{
      int a,b,c;
     
      cout<<"\t\t\t*THE BUBBLE SORT......."<<"\n"<<endl;
     
      string arnList[5]={"C","A","B","E","L"};
     
      string change;
     
      for(int x=0; x<=3; x++){
      for(a=0; a<5; a++)
      {
               for(b=a+1; b<5; b++)
               {if(arnList[a]<arnList[a+1]){
              
                          change=arnList[a];
                          arnList[a]=arnList[a+1];
                          arnList[a+1]=change;
                          }
                         
               for(c=0; c<5; c++){
               cout<<arnList[c]<<"\t";
               }
               cout<<endl;
      }
      }
      }
      getch();





#include <iostream>
#include <string.h>
#include <conio.h>
using namespace std;
main()
{
     
      string Letter[10];
     
      string swap;
     
      for(int v=0;v<10;v++){
             
       cout<<"Input your letter: "<<endl;
      
       cin>>Letter[v];
       }
       cout<<endl;
     
      for(int x=0; x<5; x++){
             
      for(int a=0; a<10; a++)
      {
               for(int b=a+1; b<10; b++)
              
               {if(Letter[a]>Letter[a+1]){
              
                          swap=Letter[a];
                         
                          Letter[a]=Letter[a+1];
                         
                          Letter[a+1]=swap;
                         
                          }
                         
               for(int c=0; c<10; c++){
                      
                      
               cout<<Letter[c]<<"\t";
               }
               cout<<endl;
      }
      }
      }
      getch();
      return 0;
}

      return 0;
}

No comments:

Post a Comment