-
Notifications
You must be signed in to change notification settings - Fork 0
/
listinterface.py
149 lines (119 loc) · 4.28 KB
/
listinterface.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
"""
File: listinterface.py
Author: Professor Lambert
Editor: Leigh Stauffer
Project 8
"""
class ListInterface(object):
"""Interface for all list types."""
# Constructor
def __init__(self, sourceCollection = None):
"""Sets the initial state of self, which includes the
contents of sourceCollection, if it's present."""
pass
# Accessor methods
def isEmpty(self):
"""Returns True if len(self) == 0, or False otherwise."""
return True
def __len__(self):
"""-Returns the number of items in self."""
return 0
def __str__(self):
"""Returns the string representation of self."""
return ""
def __iter__(self):
"""Supports iteration over a view of self."""
return None
def __add__(self, other):
"""Returns a new instance of the type of self
containing the contents of self and other."""
return None
def __eq__(self, other):
"""Returns True if self equals other,
or False otherwise."""
return False
def __getitem__(self, i):
"""Precondition: 0 <= i < len(self)
Returns the item at position i.
Raises: IndexError."""
return None
def count(self, item):
"""Returns the number of instances of item."""
return 0
def index(self, item):
"""Precondition: item is in the list.
Returns the position of item.
Raises: ValueError if the item is not in the list."""
return 0
# Mutator methods
def clear(self):
"""Makes self become empty."""
pass
def add(self, item):
"""Inserts item at the end of the list."""
pass
def append(self, item):
"""Inserts item at the end of the list."""
pass
def remove(self, item):
"""Precondition: item is in self.
Raises: ValueError if item in not in self.
Postcondition: item is removed from self."""
pass
def insert(self, i, item):
"""Inserts the item at position i."""
pass
def pop(self, i = None):
"""Precondition: 0 <= i < len(self).
Removes and returns the item at position i.
If i is None, i is given a default of len(self) - 1.
Raises: IndexError."""
return None
def __setitem__(self, i, item):
"""Precondition: 0 <= i < len(self)
Replaces the item at position i with item.
Raises: IndexError."""
pass
def listIterator(self):
"""Returns a list iterator on self."""
return None
class ListIteratorInterface(object):
"""Interface for all list iterator types."""
def first(self):
"""Returns the cursor to the beginning of the backing store."""
pass
def hasNext(self):
"""Returns True if the iterator has a next item or False otherwise."""
return False
def next(self):
"""Preconditions: hasNext returns True
The list has not been modified except by this iterator's mutators.
Returns the current item and advances the cursor to the next item."""
return None
def last(self):
"""Moves the cursor to the end of the backing store."""
pass
def hasPrevious(self):
"""Returns True if the iterator has a previous item or False otherwise."""
return False
def previous(self):
"""Preconditions: hasPrevious returns True
The list has not been modified except by this iterator's mutators.
Returns the current item and moves the cursor to the previous item."""
return None
def replace(self, item):
"""Preconditions: the current position is defined.
The list has not been modified except by this iterator's mutators.
Replaces the items at the current position with item."""
pass
def insert(self, item):
"""Preconditions:
The list has not been modified except by this iterator's mutators.
Adds item to the end if the current position is undefined, or
inserts it at that position."""
pass
def remove(self):
"""Preconditions: the current position is defined.
The list has not been modified except by this iterator's mutators.
Pops the item at the current position."""
pass