help please i have a program that i made its ascending and descending sorting. i used a template but its not descending can someone help me please. i know what my problem is but i dont know how to fix it. the problem is that this function fun(k,m,'d'); is not passing the parameter 'd' to the template. why is that
Code:
#include <iostream>
using namespace std;
template <typename mytype>
void fun2(mytype a[], int n)
{
int i;
for(i=0;i<n;++i)
cout<<a[i]<<" ";
cout<<endl;
}
template <typename mytype>
void fun (mytype a[], int b, char c='a')
{
mytype temp;
int i, j;
if(c='a')
{
for(i=0;i<b-1;i++)
{
for(j=i+1;j<b;j++)
{
if(a[i] > a[j]) //ascending
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
}
else if (c='d')
{
for(i=0;i<b-1;i++)
{
for(j=i+1;j<b;j++)
{
if(a[i] < a[j]) //descending
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
}
}
int main ()
{
char x='t',y='a',z='s';
int n,m,tony,i;
cout<<"how big do you want your array #1";
cin>>n;
cout<<"\nhow big do you want your array #2";
cin>>m;
int *u=new int[n];
double *k=new double[m];
cout<<"\n";
for(i=0;i<n;i++)
{
cout<<"Enter the data (array 1): ";
cin>>u[i];
}
for(i=0;i<m;i++)
{
cout<<"Enter the data (array 2): ";
cin>>k[i];
}
fun(u,n);
fun(k,m,'d'); // d is not overwriting the template. meaning is not passing the parameter d
fun2(u, n);
fun2(k, m);
cin.sync();
cin.get();
return 0;
}