Implement an array-based queue. To avoid moving elements with each insertion or deletion, you will implement your queue, such that the ends of the array are connected and produce the abstraction of a ring (see graphic). The first element will be inserted at index 0, the second elements at index 1, etc. The first element to be removed is at index 0 as well, since we are implementing a queue, which is a FIFO structure (first in-first out). After removal of an element, you will not move all subsequent elements! The first few spots may become vacant after a few removals. When then the array is filled up to its last spot (n-1), you will start inserting at index 0 again and continue incrementing. However, you can not override an existing element, i.e. the queue may get full. You have to implement a class for your queue, which contains function for all of the queue operations to be implemented. The constructor must take the queue size as a parameter.
Once the program is started, it will print out the prompt "queue " ( is followed by a whitespace):
You will implement the commands "new", "enqueue", "dequeue", "print" and "quit":
New takes 1 argument, representing the size of the queue. Your program will now generate a queue of the indicated size. Initialize all values to -1. -1 will be used to represent vacant spots. Then repeat the prompt. queue new 8
Enqueue takes a single integer as an argument. The element will be inserted into the queue in the corresponding spot. It the queue is full, print out an error message Then repeat the prompt.
queue enqueue 4 queue enqueue 7 queue enqueue 2 queue enqueue 6
Dequeue does not take any arguments. It removes the first element in the queue and prints it. If the queue is empty, print out an error message. Then repeat the prompt.
Print takes no arguments. It prints out the contents of the array starting at index 0. Using list notatiton wrapt the output in paranthesis and separate the elements by commas. Then repeat the prompt.
Exit the program quit quit
• If the queue is full when the user tries to insert an element, print out an error message starting with "Error!". (Do not capitalize the entire word "Error")
• If the queue is empty when the user tries to remove an element, print out an error message starting with "Error!". (Do not capitalize the entire word "Error")
• If the user types a command that is not supported, print out an error message starting with "Error!". (Do not capitalize the entire word "Error")
Submit AT LEAST the following files:
• Your main file controling the flow of the program
• The prototype file for your queue class.
• The implementation file for your queue class.
Example of program execution:
queue new 5 queue dequeue
Error! There are no elements.
queue enqueue 4 queue enqueue 8 queue enqueue 3 queue enqueue 1 queue enqueue 3 queue print (4,8,3,1,3)
queue print (-1,8,3,1,3) queue dequeue
8 queue print (-1,-1,3,1,3)
3 queue print (-1,-1,-1,1,3) queue enqueue 5 queue print (5,-1,-1,1,3) queue enqueue 2 queue print (5,2,-1,1,3) queue enqueue 2 queue enqueue 9
Error! Already full.
Your program will be judged on the following:
• 16 points - Passes I/O requirements
• 16 points - Code satisfies requirements of assignment
• 8 points - Professional coding style
- 2 points Adequate comments
- 2 points Modularity (small main function, separate functions, etc) - 2 points Readability (line length, indentation, variable names)