-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLesson13.cpp
More file actions
105 lines (100 loc) · 1.54 KB
/
Lesson13.cpp
File metadata and controls
105 lines (100 loc) · 1.54 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
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
100
101
102
103
104
105
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef struct Node{
int data;
Node* next;
Node* prev;
};
Node* insertb(Node* head, int d)
{
Node* temp=new Node();
temp->data=d;
temp->next=NULL;
if(head==NULL)
{
head=temp;
}
else
{
temp->next=head;
head->prev=temp;
temp->prev=NULL;
head=temp;
}
return head;
}
Node* inserte(Node* head,int d)
{
Node* temp=new Node();
temp->data=d;
temp->next=NULL;
if(head==NULL)
{
head=temp;
}
else
{
while(head->next!=NULL)
{
head=head->next;
}
temp->prev=head;
head->next=temp;
}
return head;
}
void print(Node* head)
{
while(head!=NULL)
{
cout<<head->data<<" ";
head=head->next;
}
cout<<endl;
}
void reversep(Node* head)
{
while (head->next!=NULL)
{
head=head->next;
}
while(head!=NULL)
{
cout<<head->data<<" ";
head=head->prev;
}
cout<<endl;
}
int main()
{
Node* head;
head=NULL;
int d;
int option;
while(1)
{
cout<<"1.Insert at head"<<endl<<"2.insert at tail"<<endl<<"3.print"<<endl<<"4.reverse print"<<endl;
cin>>option;
if(option==4)
{
reversep(head);
}
else if(option==1)
{
cout<<"insert data"<<endl;
cin>>d;
head=insertb(head,d);
}
else if(option==2)
{
cout<<"insert data"<<endl;
cin>>d;
head=inserte(head,d);
}
else if(option==3)
{
print(head);
}
}
}