CP104 Lecture Notes - Lecture 6: Double-Ended Queue, Data Element, Iterator
hayjayshay and 38575 others unlocked
2
CP104 Full Course Notes
Verified Note
2 documents
Document Summary
__updated__ = 2017-03-03 from copy import deepcopy class _dequenode: def __init__(self, value, _prev, _next): Preconditions: value - data value for node (?) Initializes a deque node that contains a copy of value and links to the previous and next nodes in the deque. self. _data = deepcopy(value) self. _prev = _prev self. _next = _next return class deque: def __init__(self): Initializes an empty deque. self. _front = none self. _rear = none self. _next = none self. _count = 0 return def is_empty(self): True if the deque is empty, false otherwise. return self. _front is none def __len__(self): Postconditions: returns the number of values in the deque. return self. _count def insert_front(self, value): Inserts a copy of value into the front of the deque. Inserts a copy of value into the rear of the deque. Removes and returns value from the front of the deque. Removes and returns value from the rear of the deque.