-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.23-Orderedlist.py
More file actions
36 lines (30 loc) · 961 Bytes
/
3.23-Orderedlist.py
File metadata and controls
36 lines (30 loc) · 961 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
#! /usr/bin/env python3
class OrderedList:
def __init__(self):
self.head = None
def search(self, item):
current = self.head
found = False
stop = False
while current.get_data() != None and not found and not stop:
if current.get_data() == item:
found = True
else:
if current.get_data() > item:
stop = True
else:
current = current.get_next()
return found
def add(self, item):
current = self.head
previous =None
while item > current.get_data() and not current.is_empty():
previous = current
current = current.get_next()
if current == None:
temp = Node(item)
previous.set_next(temp)
elif previous == None:
temp = Node(item)
self.head = temp
temp.set_next(current)