-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListNode.py
More file actions
38 lines (31 loc) · 874 Bytes
/
ListNode.py
File metadata and controls
38 lines (31 loc) · 874 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
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class ListNode(object):
def __init__(self, x):
self.val = x
self.next = None
class List_to_Link(object):
def __init__(self, sequence):
if not sequence:
self.head = None
self.head = ListNode(sequence[0])
current = self.head
for item in sequence[1:]:
current.next = ListNode(item)
current = current.next
class Link_to_List(object):
def __init__(self, head):
if not head:
self.lst = None
self.lst = []
while head:
self.lst.append(head)
head = head.next
def print_list(self):
a = []
for item in self.lst:
a.append(item.val)
print(a)