// See in simple word with doubly linked list we can travers backword in to the linked list.
// So previously we were able to travers only from head to tail but now we will be able to travers tail to head also.
// Lets build doubly linked list by self
// NOTE : THERE IS SOME ISSUE WITH DOUBLY LINKED LIST EVEN I HAVE DONE SAME CODE STILL ITS PRINTING SOME WEIRD STUFF. LOOK INTO ANOTHER RESOURCE FOR
// THIS AND NEED TO CODE HERE FROM ANOTHER RESOURCE.
// See with doubly linked list you can traverse backword and this can help us in look up operation but at same time its bit hard to manage and also
// operation are bit slower then singly list because we have less to manage there also doubly linked list required bit extra space as we are managing
// prev state also.
// MOST OF TIME IN INTERVIEW YOU WILL BE ASKED SINGLY LINKED LIST AND GOOD TO HAVE BROAD KNOWLEDGE OF DOUBLY LINKED LIST.
class Node {
constructor(value){
this.value = value;
this.next = null;
this.prev = null;
}
}
class DoublyLinkedList {
constructor(value){
this.head = new Node(value)
this.tail = this.head;
this.length = 1;
}
append(value){
if(!value) return;
let newNode = new Node(value);
newNode.prev = this.tail
this.tail.next = newNode;
this.tail = newNode;
this.length++;
return this;
}
}
let dList = new DoublyLinkedList(10);
dList.append(15);
console.log(dList)