-
Notifications
You must be signed in to change notification settings - Fork 0
/
doublyLinkedList.cpp
60 lines (57 loc) · 978 Bytes
/
doublyLinkedList.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
#include<bits/stdc++.h>
struct Node
{
int data;
Node* next;
Node* prev;
};
Node* head;
void insert(int data)
{
Node* temp = new Node();
if(head == NULL)
{
temp->data = data;
temp->next = NULL;
temp->prev = NULL;
head = temp;
}
}
void forwardPrint()
{
Node* temp = head;
while(head->next!=NULL)
{
cout<<temp->data;
temp = temp->next;
}
}
void insertNode(int data)
{
Node* temp = getNewNode(data);
if(head == NULL)
head = temp;
head->prev = temp;
temp->next = head;
head = temp;
}
void insertAttail(int data)
{
Node* temp = head;
Node* newNode = getNewNode(int data);
if(root == NULL)
head = newNode;
while(temp->next != NULL)
temp =temp->next;
temp->next = newNode;;
newNode->prev = temp;
}
int main()
{
head = NULL;
insert(2);
insert(4);
insert(6);
insert(8);
return 0;
}