forked from gods-mack/Workspace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
99 lines (57 loc) · 726 Bytes
/
test.cpp
File metadata and controls
99 lines (57 loc) · 726 Bytes
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include<iostream>
using namespace std;
struct node
{int data;
node *next;
};
class list
{
node *head,*tail;
public:
list() { head=NULL; tail=NULL; }
void add(int x)
{
node *n=new node;
n->data=x;
if(head==NULL)
{
head=tail=n; }
else
{
n->next=NULL;
tail->next=n;
tail=n;
}
}
void reverse()
{
node *p,*n,*c;
c=head;
p=NULL;
while(c!=NULL)
{ n=c->next;
c->next=p;
p=c;
c=n;
}
head=p;
}
void print()
{
node *tmp;
tmp=head;
while(tmp!=NULL)
{cout<<tmp->data<<" "; tmp=tmp->next; }
}
};
int main()
{
list a;
a.add(43);
a.add(76);
a.add(34);
a.add(72);
a.add(87);
a.reverse();
a.print();
}