-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoublyLinkedList.js
More file actions
58 lines (51 loc) · 1.84 KB
/
Copy pathdoublyLinkedList.js
File metadata and controls
58 lines (51 loc) · 1.84 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
var DoublyLinkedList = function(prev, next, data, head){
this.prev = null;
this.next = null;
this.data = null;
this.head = false;
this.tail = false;
this.setPrev = function(prev){
this.prev = prev;
}
this.setNext = function(next){
this.next = next;
}
this.setHead = function(head){
this.head = head;
}
this.setTail = function(tail){
this.tail = tail;
}
/*var getPrev = function(){
return this.prev;
}
var getNext = function(){
return this.next;
}*/
this.setData = function(data){
this.data = data;
}
}
var nodeOne = new DoublyLinkedList();
nodeOne.setData(5);
nodeOne.setHead(true);
var nodeTwo = new DoublyLinkedList();
nodeTwo.setData(51);
nodeOne.setNext(nodeTwo);
nodeTwo.setPrev(nodeOne);
var nodeThree = new DoublyLinkedList();
nodeThree.setData(33);
nodeTwo.setNext(nodeThree);
nodeThree.setPrev(nodeTwo);
var nodeFour = new DoublyLinkedList();
nodeThree.setNext(nodeFour);
nodeFour.setData(91);
nodeFour.setNext(null);
nodeFour.setPrev(nodeThree);
nodeFour.setTail(true);
document.querySelector('#nodeOne').innerHTML = "Getting value through Node 2's previous access " + nodeTwo.prev.data;
document.querySelector('#nodeTwo').innerHTML = "Getting value through double preving node 4 " + nodeFour.prev.prev.data;
document.querySelector('#nodeThree').innerHTML = "Getting value through double nexting from node 1 " + nodeOne.next.next.data;
document.querySelector('#nodeFour').innerHTML = "Getting value through triple nexting from one " + nodeOne.next.next.next.data;
document.querySelector('#isHead').innerHTML = `Node one ${nodeOne.head ? ' is ': ' is not '} the head.`;
document.querySelector('#isTail').innerHTML = `Node three ${nodeThree.tail ? ' is ' : ' is not '} the tail, and Node 4 ${nodeFour.tail ? ' is ' : ' is not '} the tail.`