-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinklsit.cpp
83 lines (70 loc) · 920 Bytes
/
linklsit.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include<iostream>
using namespace std;
struct Node
{
int val;
Node* next;
}*head,*current,*tail,*next,*prev;
void insert(int a)
{
Node * node=new Node();
node->val=a;
node->next=NULL;
if(head==NULL)
{
head=node;
tail=node;
}
else
{
tail->next=node;
tail=tail->next;
}
}
void recrev(Node* p)
{
if(p->next==NULL)
{
head=p;
return;
}
recrev(p->next);
Node*q=p->next;
q->next=p;
p->next=NULL;
}
void reverse()
{
current=head;
prev=NULL;
while(current!=NULL)
{
next=current->next;
current->next=prev;
prev=current;
current=next;
}
head=prev;
}
void printnode()
{ Node *temp=head;
while(temp!=NULL)
{
cout<<temp->val<<" ";
temp=temp->next;
}
cout<<"\n";
}
int main()
{
insert(1);
insert(2);
insert(3);
insert(5);
insert(100);
printnode();
//reverse();
recrev(head);
printnode();
return 0;
}