File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ // Lexicographic sorting is the way of sorting words based on the alphabetical order of their component letters.
2+
3+ #include <stdio.h>
4+ #include <string.h>
5+ void main ()
6+ {
7+ char str [20 ][20 ], temp [20 ];
8+ int n , i , j ;
9+ printf ("Enter the Number of Strings:\n" );
10+ scanf ("%d" , & n );
11+
12+ // Getting strings input
13+ printf ("Enter the Strings:\n" );
14+ for (i = 0 ; i < n ; i ++ )
15+ {
16+ scanf ("%s" , str [i ]);
17+ }
18+
19+ // storing strings in the lexicographical order
20+ for (i = 0 ; i < n - 1 ; i ++ )
21+ {
22+ for (j = 0 ; j < n - 1 - i ; j ++ )
23+ {
24+ if (strcmp (str [j ], str [j + 1 ]) > 0 )
25+ {
26+ // swapping strings if they are not in the lexicographical order
27+ strcpy (temp , str [j ]);
28+ strcpy (str [j ], str [j + 1 ]);
29+ strcpy (str [j + 1 ], temp );
30+ }
31+ }
32+ }
33+ printf ("Strings in the Lexicographical Order is:\n" );
34+ for (i = 0 ; i < n ; i ++ )
35+ {
36+ puts (str [i ]);
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments