For the descending sort, it only moves the highest number to the correct spot and leaves the other numbers in ascending order. Can anyone tell me what I am doing wrong?
#include<iostream.h>
#include<cmath>
void sortit(int x[], int n)
{
int temp,i,j;
for ( i=0;i<n;i++ )
for ( j=i;j<n;j++ )
if ( x[i]>x[j] )
{
temp=x[i];
x[i]=x[j];
x[j]=temp;
}
}
void reversesort(int x[], int n)
{
int temp,i,j;
for ( i=0;i<n;i++ )
for ( j=1;j<n;j++ )
if ( x[i]<x[j] )
{
temp=x[i];
x[i]=x[j];
x[j]=temp;
}
}
main()
{
int num[20];
int max=19;
int i;
for ( i=0;i<20;i++ )
{
cin>>num[i]; //
}
sortit(num,max);
cout<<"The list in ascending order is: "<<endl;
for ( int i=0;i<max;i++ )
cout<<num[i]<<"\n";
reversesort(num,max);
cout<<"The list in descending order is: "<<endl;
for ( int i=0;i<max;i++ )
cout<<num[i]<<"\n";
}