XIIB-CS-(ARRAY-SELECTION , INSERTION, BUBBLE SORT

#include<conio.h>
#include<iostream.h>
void main()
{
int a[50];
int i,j,n,smallest,temp;
//clrscr();  
cout<<"\n                     SELECTION SORT  \n";
cout<<"   ENTER TOTAL NO. OF ELEMENTS ( N<=50 )TO BE SORTED :   ";
cin>>n;
cout<<"   NOW START DADA ENTRY...  \n";
for(j=0;j<n;j++)
  {
      cout<<"\n Enter element no. "<<(j+1)<<'\t';
      cin>>a[j];
  }
for(i=0;i<n-1;i++)
{
   smallest=i;
   for(j=i+1;j<n;j++)
                 if(a[smallest]>a[j])
                             smallest=j;
   temp=a[i];
   a[i]=a[smallest] ;
   a[smallest]=temp;
 }
cout<<"\n RESULT :  ARRAY AFTER SORTING IS  \n";
for(j=0;j<n;j++)
            cout<<a[j]<<"   ";
cout<<endl;
getch();
}
..........................................................................................................
.........................................................................................................

#include<conio.h>
#include<iostream.h>
void main()
{
int a[50];
int i,j,n,temp;
clrscr();                                             
cout<<"\n                     INSERTION SORT  \n";
cout<<"   ENTER TOTAL NO. OF ELEMENTS ( N<=50 )TO BE SORTED :   ";
cin>>n;
cout<<"   NOW START DADA ENTRY...  \n";
for(j=0;j<n;j++)
{
  cout<<"\n Enter element no. "<<(j+1)<<'\t';
  cin>>a[j];
}
for(i=0;i<n-1;i++)
{     temp=a[i+1];
       j=i;
      while((a[j]>temp)&&(j>=0))
               {
                   a[j+1]=a[j];
                   j--;
               }
      a[j+1]=temp;
}
cout<<"\n   RESULT :  ARRAY AFTER SORTING IS  \n";
for(j=0;j<n;j++)
cout<<a[j]<<"   ";
cout<<endl;
getch();
}
............................................................................................................
............................................................................................................
#include<conio.h>
#include<iostream.h>
void main()
{
int a[50];
int i,j,n,temp;
//clrscr();  
cout<<"\n                     BUBBLE SORT  \n";
cout<<"   ENTER TOTAL NO. OF ELEMENTS ( N<=50 )TO BE SORTED :   ";
cin>>n;
cout<<"   NOW START DADA ENTRY...  \n";
for(j=0;j<n;j++)
  {
      cout<<"\n Enter element no. "<<(j+1)<<'\t';
      cin>>a[j];
  }
for(i=0;i<n;i++)
   for(j=0;j<n-i;j++)
            {
              if(a[j]>a[j+1])
                   {
                       temp=a[j];
                       a[j]=a[j+1];
                       a[j+1]=temp;
                    }
            }
cout<<"\n   RESULT :  ARRAY AFTER SORTING IS  \n";
for(j=0;j<n;j++)
            cout<<a[j]<<"   ";
cout<<endl;
getch();
}
 

Popular posts from this blog

XII- CS-- SOLVED SQL queries (SQL PRACTICAL ASSIGNMENS)

SQL--HOME ASSIGNMENTS(XII Class)

Python-MySQL Connectivity