How to add descending order when sorting strings? I already have an ascending one.

What i want is when the user presses D then the strings he/she inputted would be sorted descendingly like what i did with the ascending part and it works just fine but i don't know how to add the two.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<conio.h>
#include<stdio.h>
#include<iostream.h>
#include<string.h>

char a[50][50],*tmp,*tmp2;
int num,p,c,q,t,choice;

void main()
{
	clrscr();
	cout<<"Input number of data: ";
	cin>>num;

	for(int x=0;x<num;x++)
	gets(a[x]);
	cout<<"\n\nUnsorted data: ";
	for(int y=0;y<num;y++)
	cout<<a[y]<<",";
	cout<<"\nHow would you like to sort these data [A]scending or [D]escending?";

	p=num-1;

	for(p;p>0;p--)
	{
	 for(c=0;c<p;c++)
	  {
	    if(stricmp(a[c],a[c+1])>0) */all i know is that when i change it to < it would be sorted descendingly i dont know how to add both ascending and descending option */
	     {
	      strcpy(tmp,a[c]);
	      strcpy(a[c],a[c+1]);
	      strcpy(a[c+1],tmp);
	     }
	  }
	}
	choice=getch();
	if(choice=='A' | choice=='a')
	cout<<"\n Sorted data in ascending order: ";
	 for(int z=0;z<num;z++)
	  cout<<a[z]<<",";








	getch();


}
Topic archived. No new replies allowed.