forked from SamirPaulb/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path08.py
50 lines (36 loc) · 1008 Bytes
/
08.py
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
class Node:
def __init__(self,data):
self.data = data
self.ref = None
class LinkedList:
def __init__(self):
self.head = None
def print_LL(self):
if self.head is None:
print("The Linked List is Empty")
else:
n = self.head
while n is not None:
print(n.data)
n = n.ref
def add_begin(self,data):
if self.head is None:
self.head = Node(data)
else:
new_node = Node(data)
new_node.ref = self.head
self.head = new_node
def add_end(self,data):
if self.head is None:
self.head = Node(data)
else:
new_node = self.head
while new_node.ref is not None:
new_node = new_node.ref
new_node.ref = Node(data)
LL1 = LinkedList()
LL1.add_begin(10)
LL1.add_end(2000)
LL1.add_begin(20)
LL1.add_end(300)
LL1.print_LL()