-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList.py
More file actions
40 lines (34 loc) · 1015 Bytes
/
LinkedList.py
File metadata and controls
40 lines (34 loc) · 1015 Bytes
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
class ListNode(object):
def __init__(self, val=0, next=None):
self.val = val
self.next = next
def __repr__(self):
out = "LinkedList Node: " + str(self.val)
cur = self.next
while cur:
out += "->" + str(cur.val)
cur = cur.next
out += " [end]"
return out
def __str__(self):
out = "LinkedList Node: " + str(self.val)
cur = self.next
while cur:
out += "->" + str(cur.val)
cur = cur.next
out += " [end]"
return out
def insert(self, val=0, next=None):
if self.next is None:
self.next = ListNode(val=val, next=next)
else:
cur = self.next
while cur.next:
cur = cur.next
cur.next = ListNode(val=val, next=next)
class LinkedList(object):
def __init__(self, head):
# head = ListNode
self.head = head
def __repr__(self):
pass