-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLists.py
51 lines (41 loc) · 834 Bytes
/
Lists.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
45
46
47
48
49
50
51
class LinkedList:
""" Custom Linked List class"""
val = "x"
next = None
def __init__(self, val):
self.val = val
def printLinkedList(head):
item = head
while item is not None:
print(item.val)
item = item.next
def removeNth(head , ind):
if ind == 0:
return head.next
prev = head
item = head.next
i = 1
while item is not None:
if i == ind:
prev.next = item.next
break
i = i + 1
prev = item
item = item.next
return head
A = LinkedList("A")
B = LinkedList("B")
C = LinkedList("C")
D = LinkedList("D")
E = LinkedList("E")
F = LinkedList("F")
A.next = B
B.next = C
C.next = D
D.next = E
E.next = F
printLinkedList(A)
print("---")
HEAD = removeNth(A,1)
printLinkedList(HEAD)
print("---")