Java

Saturday, 10 January 2015

c++ program to implement selection sort

Program:

       #include<iostream.h>
       #include<conio.h>
       #include<iomanip.h>
       template<class t>
       Void selection sort(t list[],int n)
     
      {
       t temp;
       int i,j;
       For(i=0;i<not;i++)
       {
       for(j=i+1;j<n;j++)
       {
       if(list[j]<=list[i])
       {
       temp=list[j];
       list[j]=list[i];
       list[i]=temp;
       }
       }
       }
       void main()
       {
       Clrscr();
       int *a,n;
       cout<<"enter size ";
       cin>>n;
       a=new int[n];
       cout<<"enter elements are \n";
       for(int i=0;i<n;i++)
       cin>>a[i];
       selection sort(a,n);
       cout<<"sorted elements are \n";
       for(i=0;i<n;i++)
       cout<<a[i]<<"  ";
       getch();
       }



Create your own website
    Click here 

No comments:

Post a Comment