#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct linenode
{
char *line;
struct linenode *next;
};
static int compare(const void *a, const void *b)
{
return strcmp(*(const char **)a, *(const char **)b);
}
int main(void)
{
struct linenode *tree = NULL;
struct linenode *node, *next;
unsigned count, i;
char Buf[2048];
char **lines;
for(count=0; fgets(Buf, sizeof Buf, stdin) != NULL; ++count)
{
strtok(Buf, "\n");
node = (struct linenode *)malloc(sizeof(*tree));
node->line = (char *)malloc(strlen(Buf)+1);
strcpy(node->line, Buf);
node->next = tree;
tree = node;
}
lines = (char **)malloc(count * sizeof(*lines));
i = 0;
for(node = tree; node != NULL; node = next)
{
lines[i++] = node->line;
next = node->next;
free(node);
}
qsort(lines, count, sizeof(lines[0]), compare);
for(i = 0; i < count; ++i)
puts(lines[i]);
free(lines);
return 0;
}