mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 23:11:09 +00:00
Update doubly_linked_list.py (#545)
This commit is contained in:
parent
6db1994de2
commit
1b19028117
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue
Block a user