Part 15 of 15 in Sorting  

Lexicographical Sorting by animeshn

Problem statement

Given a list of strings, sort the strings in lexicographical order (dictionary order).


First line of input will contain a number T = no, of test cases. Each test case will contain 2 lines. First line will contain N = number of strings in a list. Next line will contain N strings comprising of only lower case letters ('a' to 'z') separated by space.


For each test case, print on a single line, the strings as space separated list in lexicographical order (dictionary order). There should be no space after last element in the list.

Sample Input
program sort loop sentence fragment bracket
wheel car mile meter yard
cat rat bat hat vat mat pet set met fat 
Sample Output
bracket fragment loop program sentence sort
car meter mile wheel yard
bat cat fat hat mat met pet rat set vat

Lexicographical order is the order in which strings will occur in dictionary.

To try out your code

Sign in

Sign up