Professional Documents
Culture Documents
CS 201 S24, Lecture 1b, Interfaces - ADTs
CS 201 S24, Lecture 1b, Interfaces - ADTs
CS 201 S24, Lecture 1b, Interfaces - ADTs
Queue Interface
• add(x): add the value x to the Queue
• remove(): remove the next (previously added) value, y, from the Queue and return y
List Interface
size() : return n, the length of the list
get(i) : return the value at index i
set(i, x) : set the value at position i equal to x
add(i, x) : add x at index i, shifting subsequent values one index forward
remove(i) : remove the value at index i, shifting back subsequent values one index
Dictionary Interface
add(k,v) : assign the key, k, to value, v, and add the dictionary
remove(k) : remove the key, k (and its associated value) from the dictionary
find(k) : return the value of key k.
Assessment:
1. Suppose I tried to add an element to my USet and it returned false. What does
that mean?
2. Suppose I want to remove two elements at indices x and y from my List. I call
remove(x) and then remove(y) on my List. Have I removed the correct
elements?
3. Suppose I want to find an element, x, that is greater than all elements in my
SSet. What will find(x) return?
4. I want an interface where I can add and remove elements by value, and where
duplicates are allowed.
5. I want an interface where I can find the least element in a single operation.