-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlec4_2.cpp
More file actions
53 lines (45 loc) · 860 Bytes
/
lec4_2.cpp
File metadata and controls
53 lines (45 loc) · 860 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
//Convert Array to DLL using Tail
#include<iostream>
using namespace std;
class Node
{
public:
int data;
Node *prev;
Node *next;
Node(int value)
{
data = value;
prev = NULL;
next = NULL;
}
};
int main()
{
Node *head = NULL , *tail = NULL;
//create Doubly Linked List
int arr[] = {1 , 2,3 ,4 ,5};
for(int i = 0 ; i<5;i++)
{
//Linked list doesnt exist
if(head == NULL)
{
head = new Node(arr[i]);
tail = head;
}
//Already exists
else
{
Node * temp = new Node(arr[i]);
tail->next = temp;
temp->prev = tail;
tail = temp;
}
}
Node *trav = head;
while(trav)
{
cout<<trav->data<<" ";
trav = trav->next;
}
}