-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathreverse.cpp
More file actions
50 lines (50 loc) · 698 Bytes
/
reverse.cpp
File metadata and controls
50 lines (50 loc) · 698 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
#include<iostream>
using namespace std;
struct node
{
int info;
node *next;
};
main()
{
int n,i;
node *temp,*t,*start=NULL,*newn,*current,*nextn=NULL,*prev=NULL;
while(start==NULL)
{
start=new node;
cin>>start->info;
start->next=NULL;
}
cin>>n;
for(i=0;i<n;i++)
{
newn=new node;
cin>>newn->info;
newn->next=NULL;
t=start;
while(t->next!=NULL)
t=t->next;
t->next=newn;
}
t=start;
while(t!=NULL)
{ cout<<"Before Insertion";
cout<<t->info<<" ";
t=t->next;
}
current=start;
while(current!=NULL)
{
nextn=current->next;
current->next=prev;
prev=current;
current=nextn;
}
start=prev;
t=start;
while(t!=NULL)
{
cout<<t->info;
t=t->next;
}
}