-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoublyLinkedList.cpp
More file actions
63 lines (55 loc) · 978 Bytes
/
doublyLinkedList.cpp
File metadata and controls
63 lines (55 loc) · 978 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
#include<iostream>
#include<stdlib.h>
using namespace std;
class doublyLinkedList{
private:
struct node{
int data;
node *prev;
node *next;
};
node *head=NULL, *ptr, *ptr1;
public:
void addf();
void addn();
void remove();
void display();
};
void doublyLinkedList::addf(){
ptr=(struct node*)malloc(sizeof(struct node));
cout<<endl<<"Enter Data: ";
cin>>ptr->data;
ptr->prev=NULL;
ptr->next=NULL;
head=ptr;
}
void doublyLinkedList::addn(){
ptr1=(struct node*)malloc(sizeof(struct node));
cout<<endl<<"Enter Data: ";
cin>>ptr1->data;
ptr1->prev=ptr;
ptr1->next=NULL;
ptr->next=ptr1;
ptr=ptr1;
}
void doublyLinkedList::display(){
ptr=head;
cout<<endl;
while(ptr->next!=NULL){
cout<<ptr->data<<" ";
ptr=ptr->next;
}
cout<<ptr->data;
}
int main(){
doublyLinkedList o1;
char choice='y';
o1.addf();
while (choice=='y'||choice=='Y'){
o1.addn();
cout<<endl<<"Add More?(y/n): ";
cin>>choice;
}
o1.display();
return 0;
}