Looking to test my library and implementing it so that insert function can assign the index of the rear in th e ring after the items are inserted in ring
class CircularQueue:
def __init__(self, size):
"""
-------------------------------------------------------
Initializes an empty queue. Data is stored in a list.
-------------------------------------------------------
Postconditions:
Initializes an empty queue.
-------------------------------------------------------
"""
self._values = [None] * size
return
def is_empty(self):
"""
-------------------------------------------------------
Determines if the list is empty.
Use: b = l.is_empty()
-------------------------------------------------------
Postconditions:
Returns True if the list is empty, False otherwise.
-------------------------------------------------------
"""
return len(self._values) == 0
def insert(self, value):
"""
-------------------------------------------------------
Inserts a copy of value into list.
Use: l.insert( value )
-------------------------------------------------------
Preconditions:
value - a data element (?)
Postconditions:
value is added to the list.
-------------------------------------------------------
"""
length_circ = len(self._values)
rear = 0
self._values
return
def remove(self, key):
"""
-------------------------------------------------------
Finds, removes, and returns the value in list that matches key.
Use: value = l.remove( key )
-------------------------------------------------------
Preconditions:
key - a data element (?)
Postconditions:
Returns and removes the full value matching key, otherwise
returns None.
-------------------------------------------------------
"""
index_found = self._linear_search(key)
if index_found == -1:
value = None
else:
value = self._values.remove(index_found)
return value
def peek(self):
"""
-------------------------------------------------------
Finds, removes, and returns the value in list that matches key.
Use: value = l.remove( key )
-------------------------------------------------------
Preconditions:
key - a data element (?)
Postconditions:
Returns and removes the full value matching key, otherwise
returns None.
-------------------------------------------------------
"""
index_found = self._linear_search(key)
if index_found == -1:
value = None
else:
value = self._values.remove(index_found)
return value
def is_full(self):
"""
-------------------------------------------------------
Determines if the list is empty.
Use: b = l.is_empty()
-------------------------------------------------------
Postconditions:
Returns True if the list is empty, False otherwise.
-------------------------------------------------------
"""
return len(self._values) == 0
def __len__(self):
"""
-------------------------------------------------------
Returns the size of the list.
Use: n = len( l )
-------------------------------------------------------
Postconditions:
Returns the number of values in the list.
-------------------------------------------------------
"""
return len(self._values)