-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserList.py
73 lines (60 loc) · 1.72 KB
/
userList.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
class Node:
def __init__(self, v = None):
self.value = v
self.next = None
return
def isempty(self):
if self.value == None:
return(True)
else:
return(False)
def append(self,v): # append, recursive
if self.isempty():
self.value = v
elif self.next == None:
newnode = Node(v)
self.next = newnode
else:
self.next.append(v)
return
def insert(self,v):
if self.isempty():
self.value = v
return
newnode = Node(v)
# Evchange values in self and newnode
(self.value, newnode.value) = (newnode.value, self.value)
(self.next, newnode.next) = (newnode, self.next)
return
def delete(self,v): # delete, recursive
if self.isempty():
return
if self.value == v:
self.value = None
if self.next != None:
self.value = self.next.value
self.next = self.next.next
return
else:
if self.next != None:
self.next.delete(v)
if self.next.value == None:
self.next = None
return
def __str__(self):
selflist = []
if self.value == None:
return(str(selflist))
temp = self
selflist.append(temp.value)
while temp.next != None:
temp = temp.next
selflist.append(temp.value)
return(str(selflist))
def length(self):
if self.value == None:
return(0)
elif self.next == None:
return(1)
else:
return(1 + self.next.length())