10374 - Lab11   

Description

Given a list of English names, use ‘qsort’ to sort the names in lexicographic order. The number of names is less than or equal to 10, and each length of the name is no more than 5.


The detailed rules of sorting are:
1. Sort the strings in alphabetical order. E.g. “abc” is prior to “abd”.
2. The string with smaller length has top priority. E.g. “xyz” is prior to “ABCD”.
3. The uppercase alphabet is prior to lowercase alphabet. E.g. “AA” is prior to “aA”.

You may use the following piece of code:

#include 
#include 
#include 

#define SIZE 10
#define LENGTH 6

int compare_str_ptr(const void *a, const void *b)
{
    /* your code here */
}

int main()
{

    char strs[SIZE][LENGTH] = {0};
    char *ptrs[SIZE];
    int i, N;

    scanf("%d", &N);
    for (i=0; i
  

Input

Number of names
Name 1
Name 2
Name 3


Output

Print the sorted names line by line. Each line contains one name and ends with a newline character.

Sample Input  Download

Sample Output  Download

Tags




Discuss