-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelping_functions.py
More file actions
59 lines (39 loc) · 1.22 KB
/
helping_functions.py
File metadata and controls
59 lines (39 loc) · 1.22 KB
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
52
53
54
55
56
57
58
59
import random
class Node:
def __init__(self, val):
self.val = val
self.next = None
class LinkList:
def __init__(self):
self.head = None
self.ptr = None
def push(self, new_data):
new_node = Node(new_data)
new_node.next = self.head
self.head = new_node
def get_last_node(self):
if not self.head:
return None
current = self.head
while current.next:
current = current.next
return current
def list_all_values(self, output_list):
if self.head == None:
return None
current = self.head
while current:
output_list.append(current.val)
current = current.next
def serach_value(self, target_value, output_list):
# Put the index of all target_value and its adress in the output_list
if self.head == None:
return None
current = self.head
index_count = 0
while current:
if current.val == target_value:
output_list.append((index_count, current))
index_count += 1
current = current.next
my_LinkList = LinkList()