Add Python linkedlist (#119)
* fixed incorrect links * added singly list Data structure * removed semi-column * added doubly linked list * added doubly linked list * docs: update linked list index add python double linked list in the linked list inded Co-authored-by: Arsenic <54987647+Arsenic-ATG@users.noreply.github.com>pull/120/head
parent
3168e2f6c3
commit
aa919129f2
|
@ -0,0 +1,34 @@
|
|||
# A simple Python program to create a linked list
|
||||
|
||||
# Node class
|
||||
class Node:
|
||||
def __init__(self, data):
|
||||
self.data = data
|
||||
self.next = None
|
||||
self.prev = None
|
||||
|
||||
class doubly_linked_list:
|
||||
|
||||
def __init__(self):
|
||||
self.head = None
|
||||
|
||||
# Adding data elements
|
||||
def push(self, NewVal):
|
||||
NewNode = Node(NewVal)
|
||||
NewNode.next = self.head
|
||||
if self.head is not None:
|
||||
self.head.prev = NewNode
|
||||
self.head = NewNode
|
||||
|
||||
# Print the Doubly Linked list
|
||||
def listprint(self, node):
|
||||
while (node is not None):
|
||||
print(node.data),
|
||||
last = node
|
||||
node = node.next
|
||||
|
||||
dllist = doubly_linked_list()
|
||||
dllist.push(12)
|
||||
dllist.push(8)
|
||||
dllist.push(62)
|
||||
dllist.listprint(dllist.head)
|
|
@ -19,3 +19,4 @@
|
|||
|
||||
### Python
|
||||
1. [Singly Linked List](Python/singly.py)
|
||||
2. [Doubly Linked List](Python/doubly.py)
|
||||
|
|
Loading…
Reference in New Issue