#include<stdio.h>
#include<conio.h>
#include<string.h>
#define MAX 20
char a[MAX][MAX];
void upper(char *s)
{
int i;
for(i=0;(s[i]!='\0')&&(s[i]!='\n');i++)
if((s[i]>='a')&&(s[i]<='z'))
s[i]=s[i]-32;
}
void merge(int low,int mid,int high)
{
char b[MAX][MAX];
int i=low,j=mid+1,k=low,l=0;
while(i<=mid&&j<=high)
{
if(a[i][l]<=a[j][l])
strcpy(b[k++],a[i++]);
else
strcpy(b[k++],a[j++]);
l++;
}
while(i<=mid)
strcpy(b[k++],a[i++]);
while(j<=high)
strcpy(b[k++],a[j++]);
for(i=low;i<=high;i++)
strcpy(a[i],b[i]);
}
int merge_sort(int low ,int high)
{
int mid;
if(low!=high&&low<high&&low!=mid)
{
mid=(low+high)/2;
merge_sort(low,mid);
merge_sort(mid+1,high);
merge(low,mid,high);
}
return 0;
}
void main()
{
FILE *f;
int i,n;
clrscr();
f=fopen("name.txt","r");
//if(f!=NULL)printf("vaild"); else printf("Invalid");
printf("Names:\n");
for(i=0;a[i-1][0]!='\n';i++)
fgets(a[i],150,f);
n=i-1;
for(i=0;i<n;i++)
{
upper(a[i]);
printf("\t%s",a[i]);
}
merge_sort(0,n-1);
printf("\nSorted list:\n");
for(i=0;i<n;i++)
printf("\t%s",a[i]);
getch();
}