Update doubly_linked_list.py (#545)

This commit is contained in:
Aditya Sharma 2018-10-31 13:04:55 +05:30 committed by Harshil
parent 6db1994de2
commit 1b19028117

View File

@ -2,11 +2,12 @@
- A linked list is similar to an array, it holds values. However, links in a linked list do not have indexes.
- This is an example of a double ended, doubly linked list.
- Each link references the next link and the previous one.
'''
- A Doubly Linked List (DLL) contains an extra pointer, typically called previous pointer, together with next pointer and data which are there in singly linked list.
- Advantages over SLL - IT can be traversed in both forward and backward direction.,Delete operation is more efficent'''
from __future__ import print_function
class LinkedList:
class LinkedList: #making main class named linked list
def __init__(self):
self.head = None
self.tail = None
@ -25,7 +26,7 @@ class LinkedList:
self.head = self.head.next # oldHead <--> 2ndElement(head)
self.head.previous = None # oldHead --> 2ndElement(head) nothing pointing at it so the old head will be removed
if(self.head is None):
self.tail = None
self.tail = None #if empty linked list
return temp
def insertTail(self, x):