-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathreverse.cpp
73 lines (70 loc) · 977 Bytes
/
reverse.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
#include<iostream>
struct node
{
node* prev;
int data;
node*next;
};
node *head=NULL;
node *head1=NULL;
node * getnode(int data)
{
node *temp=new node();
temp->data=data;
temp->next=NULL;
temp->prev=NULL;
return temp;
}
void insertdata(int data)
{
node *temp=getnode(data);
if(head1==NULL)
{
head1=temp;
head=temp;
return;
}
temp->prev=head;
head->next=temp;
head=temp;
}
void print()
{
node *temp=head1;
while(temp!=NULL)
{
printf("%d ",temp->data);
temp=temp->next;
}
}
void reverse()
{
node *temp=head1;
if(temp==NULL)return;
while(temp->next!=NULL)
{
temp=temp->next;
}
while(temp!=NULL)
{
printf("%d ",temp->data);
temp=temp->prev;
}
printf("\n");
}
int main()
{
int i,n,data;
printf("enter no of values you want to enter :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter data : ");
scanf("%d",&data);
insertdata(data);
printf("data is \n");
print();
printf("\nreverse of data is\n");
reverse();
}
}