Question: For this program you will implement a queue that can contain either integers, characters, or doubles. A queue is a data structure that accepts new
For this program you will implement a queue that can contain either integers, characters, or doubles. A queue is a data structure that accepts new items to be stored at the front of the queue and takes away items previously stored from the back of the queue. Thus, this is a FIFO, first in first out data structure, method of storing items. You will declare a template class for the qucue. The queue will be implemented using an array of size 3. The array will be used as a circular array. This means that, for example, if the current frontIndex of the array is 2, and another item must be added to the queue, then frontlndex must be incremented. Since the array has 3 elements, the index must go from 2 to 0. backlndex works the same way. This is implemented using the modulus operator. The class will have 3 data members: an array of SIZE 3 called q, two indexes for use with the array, frontlndex and backIndex The class will have three member functions: *a constructor a function putFront(T i) that will put a new item on the front of the queue. i is the item to be stored. Type T can be integer, character, or double. a function getBack0 that will get a previously stored item from the back of the queue. In the constructor you will initially set frontindex and backIndex both to -1. This is the indication that the queue is empty The implementation of frontlndex and backIndex is straightforward except when frontIndex and backIndex are the same. This can occur in two very different situations, when the queue is empty. For example, suppose that frontlndex is 2 and backlndex is 1, and an item is removed
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
