Sunday, February 14, 2016

 To sort 10 number in asscending order using function template.
Program:-

#include <iostream>
#include <conio.h>
using namespace std;
template <class T>
void Sort(T a[],int n)
{
    T hold;
    int i,j;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n-1-i;j++)
        {
            if(a[j]>a[j+1])
            {
                hold=a[j];
                a[j]=a[j+1];
                a[j+1]=hold;
            }
        }
    }
}
int main()
{
    int i,j;
   int x[10]={1,8,7,4,6,7,4,2,5,7};
   float y[10]={0.2,0.5,1.1,2.1,0.33,5.6,9.7,1.59,8.8,0.001};
   Sort(x,10);
   Sort(y,10);
   cout<<"------Sorted X array-----------"<<endl;
   for(i=0;i<10;i++)
   {
       cout<<x[i]<<endl;
   }
   cout<<"------Sorted Y array-----------"<<endl;

       for(j=0;j<10;j++)
       {
          cout<<y[j]<<endl;
       }
       cout<<"!!!!!!!!!!!Thank You!!!!!!!!!!!"<<endl;
       getch();


    return 0;
}

Output:-







0 comments:

Post a Comment

Translate

Sample Text

Powered by Blogger.

Every thing is possible in real world....

Contact us

Name

Email *

Message *

IT Support

Blogroll

You can replace this text by going to "Layout" and then "Page Elements" section. Edit " About "

Video

Our Facebook Page

Popular Posts

Total Pageviews