forked from HU-CS201-master/chap01
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuset.py
100 lines (87 loc) · 2.1 KB
/
uset.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
class USet:
def __init__(self):
'''Initializes member variables.
>>> uset = USet()
'''
pass
def __str__(self):
'''Returns a string representation of an object for printing.
>>> uset = USet()
>>> print(uset) # prints uset.__str__()
'''
pass
def add(self, key, val):
'''Adds the pair (key, val) to the USet if no pair with key
already exists in the USet, and returns True. Returns False if a
pair with key already exists in the USet.
>>> uset = USet()
>>> uset.add(1, 10)
True
>>> uset.add(2, 20)
True
>>> uset.add(2, 30)
False
'''
pass
def remove(self, key):
'''Removes the pair with key from the USet and returns it.
Returns None if no such pair exsits.
>>> uset = USet()
>>> uset.add(1, 10)
True
>>> uset.add(2, 20)
True
>>> uset.remove(1)
(1, 10)
>>> uset.remove(10)
>>>
'''
pass
def find(self, key):
'''Returns the pair from the USet that contains key; None if no
such pair exists.
>>> uset = USet()
>>> uset.add(1, 10)
True
>>> uset.add(2, 20)
True
>>> uset.find(1)
(1, 10)
>>> uset.find(10)
>>>
'''
pass
def size(self):
'''Returns the number of pairs currently in the USet.
>>> uset = USet()
>>> uset.size()
0
>>> uset.add(1, 10)
True
>>> uset.add(2, 20)
True
>>> uset.size()
2
>>> uset.add(2, 30)
False
>>> uset.size()
2
'''
pass
def keys(self):
'''Returns a list of keys in the USet.
>>> uset = USet()
>>> uset.keys()
[]
>>> uset.add(1, 10)
True
>>> uset.add(2, 20)
True
>>> uset.keys()
[1, 2]
>>> uset.add(2, 30)
False
>>> uset.keys()
[1, 2]
'''
pass