-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkedList.py
83 lines (70 loc) · 1.91 KB
/
linkedList.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
class Node:
def __init__(self, Data):
self.data = Data
self.next = None
@property
def Data(self):
return self.data
@property
def Next(self):
return self.next
@property
def Data(self, data):
self.data = data
@property
def Next(self, neext):
self.next = neext
class UnorderedList:
def __init__(self):
self.head = None
@property
def isEmpty(self):
return None == self.head
def add(self, data):
temp = Node(data)
temp.next = self.head
self.head = temp
@property
def size(self):
current = self.head
count = 0
while None != current:
count = count + 1
current = current.next
return count
def search(self, data):
current = self.head
found = False
while None != current.next:
if current.data == data:
found = True
break
else:
current = current.next
else:
if current.data == data:
found = True
return found
def remove(self, data):
if not self.search(data):
return -1
else:
current = self.head
prev = None
while True:
if current.data == data:
break
else:
prev = current
current = current.next
if None == prev:
self.head = current.next
else:
prev.next = current.next
def show_list(self):
current = self.head
data_lst = []
while None != current:
data_lst.append(current.data)
current = current.next
return data_ lst