Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions sortwithtemplatebubblesort
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
template<class T>//standard template library
void sort(T a[],int s)//sorts in descending order
{
T temp;
for (int i=0;i<s-1;i++)//technique of bubble sort
{
for (int j=0;j<s-i-1;j++)
{
if (a[j+1]>a[j])
{
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
}
}
}
int main()
{
int s;
int b[100];
char c[100];
cout<<"Enter the number of values to be sorted"<<endl;
cin>>s;
cout<<"Enter the array of integers"<<endl;
fflush(stdin);
for (int i=0;i<s;i++)
{
fflush(stdin);
cin>>b[i];
}
sort(b,s);//calls the sort function that sorts with templates
for (int i=0;i<s;i++)
{
cout<<b[i]<<" ";
}
fflush(stdin);
return 0;
}