c++ lab exam
Bubble Sort
#include<iostream>
#include<conio>
template<class t>
void bubble(t a[])
{
for(int i=1;i<5;i++)
{
for(int j=1;j<5;j++)
{
if(a[j]>a[j+1])
{
swap(a[j],a[j+1]);
}
}
}
cout<<"After Bubble Sort:\n";
for(int i=1;i<5;i++)
{
cout<<a[i]<<endl;
}
}
template <class x>
void swap(x &v, x& m)
{ x temp ;
temp= v;
v=m;
m=temp;
}
int main()
{
int t[5]={55,22,111,2,1};
cout<<"Before Bubble Sort:\n";
for(int i=1;i<5;i++)
{
cout<<t[i]<<endl;
}
bubble(t);
getch();
return 0;
}
#include<iostream>
#include<conio>
template<class t>
void bubble(t a[])
{
for(int i=1;i<5;i++)
{
for(int j=1;j<5;j++)
{
if(a[j]>a[j+1])
{
swap(a[j],a[j+1]);
}
}
}
cout<<"After Bubble Sort:\n";
for(int i=1;i<5;i++)
{
cout<<a[i]<<endl;
}
}
template <class x>
void swap(x &v, x& m)
{ x temp ;
temp= v;
v=m;
m=temp;
}
int main()
{
int t[5]={55,22,111,2,1};
cout<<"Before Bubble Sort:\n";
for(int i=1;i<5;i++)
{
cout<<t[i]<<endl;
}
bubble(t);
getch();
return 0;
}

Comments
Post a Comment