-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsgLLnameSort.cpp
More file actions
70 lines (68 loc) · 1.09 KB
/
sgLLnameSort.cpp
File metadata and controls
70 lines (68 loc) · 1.09 KB
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
69
70
//LLc of names and sort it in alphabetical order
#include<iostream>
#include<string>
using namespace std;
#define null 0
struct dict
{
string data;
dict *next;
};
dict *first,*temp,*ttemp,*i,*j;
void init()
{
first=temp=ttemp=null;
}
void addnode()
{
ttemp=new dict;
cin>>ttemp->data;
ttemp->next=null;
if(first==null)
first=ttemp;
else
temp->next=ttemp;
temp=ttemp;
}
void disp()
{
temp=first;
while(temp!=null)
{
cout<<temp->data<<"\n";
temp=temp->next;
}
}
void inorder()
{
string tempdata;
for(i=first;i!=null;i=i->next)
{
for(j=i->next;j!=null;j=j->next)
{
if(i->data>j->data)
{
//swap
tempdata=i->data;
i->data=j->data;
j->data=tempdata;
}
}
}
}
int main()
{
init();
int n;
cout<<"enter number of names u want to enter: ";
cin>>n;
for(int i=1;i<=n;i++)
{
addnode();
}
cout<<"\noriginal sequence\n";
disp();
cout<<"\n";
inorder();
disp();
}