-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlink.cpp
More file actions
76 lines (61 loc) · 1.01 KB
/
link.cpp
File metadata and controls
76 lines (61 loc) · 1.01 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
71
#include<iostream>
using namespace std;
struct node
{int data;
string name;
node *next;
};
class list
{ node *h,*t;
public:
list()
{ h=NULL; t=NULL; }
void add(int x,string str)
{ node *n= new node;
n->data=x;
n->name=str;
if(h==NULL) {
t=n; h=n; }
else {
t->next=n;
t=t->next ; }
}
void get()
{ int num; string nme;
cout<<"Enter number"<<endl;
cin>>num; cout<<"Enter name "<<endl;
cin>>nme;
add(num,nme);
}
void sort()
{
int hold=h->data;
while(h!=NULL)
{
h=h->next;
if(hold>(h->data))
{ h->data=hold;
hold=h->data;
}
}
}
void print()
{ node *tmp; tmp=h;
while(h!=NULL)
{
cout<<h->data<<" "<<h->name<<endl;
h=h->next; }
}
};
int main()
{ int i;
list a,b,c;
for(int i=0;i<5;i++)
{ a.get(); }
/** a.add(4);
a.add(5);
a.add(2);
a.add(15);
// a.sort();**/
a.print();
}