-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1NMESORT.CPP
68 lines (67 loc) · 1016 Bytes
/
1NMESORT.CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<conio.h>
#include<iostream.h>
#include<string.h>
#include<stdio.h>
void main()
{
char str[50][5];
int i,j;
char temp[100];
char *p[50];
int n;
cout<<"\n enter number of name u want to enter";
cin>>n;
cout<<"ENTER NAMES";
for(i=0;i<n;i++)
{
for(j=0;j<1;j++)
{
scanf("%s",&str[i][j]);
p[i]=&str[i][j];
}
}
/*for(i=0;i<n;i++)
{
for(j=0;j<1;j++)
{
if(strcmp(str[i][j],str[i+1][j])>0);
{
strcpy(temp,str[i+1][j]);
strcpy(str[i+1][j],str[i][j]);
strcpy(str[i][j],temp);
}
}
}
cout<<"\n sorted string is";
for(i=0;i<n;i++)
{
for(j=0;j<1;j++)
{
cout>>str[i][j];
}
}
getch();
} */
i=0;
while(i<n)
{
if(strcmp(*p[i],*p[i+1])>0);
{
strcpy(temp,*p[i+1]);
strcpy(*p[i+1],*p[i]);
strcpy(*p[i],temp);
}
i++;
}
cout<<"sorted string is";
/*for(i=0;i<n;i++)
{
for(j=0;j<1;j++)
{
cout>>str[i][j];
}
} */
for(i=0;i<n;i++)
cout<<*(p+i)<<"\n";
getch();
}