Question: Using C 2) Constructing a Queue Queue is a data collection in which the entities in the collection are kept in order and the operations
Using C
2) Constructing a Queue Queue is a data collection in which the entities in the collection are kept in order and the operations on the collection are the addition of entities to the rear terminal position, known as enqueue, and removal of entities from the front terminal position, known as dequeue. This makes the queue a First-In-First-Out (FIFO) data structure. As we mentioned in the class, stack is a similar data collection that adds/removes entities in a First-In-Last-Out (FILO) manner. In this assignment, you need to construct a queue of integers by implementing its enqueue and dequeue operations using two stacks in the following way (implementation of a stack and its push & pop operations in C can be found in the textbook and in slides). void enqueue (int entity): The enqueue operation can be done by simply pushing the entity in the first stack. 1 int dequeue(): In order to implement dequeue operation, you need to first transfer all of the entities stored in the first stack to the second one using a sequence of alternating pop and push operations on the first and second stacks respectively (i.e. popping an integer from the first stack and pushing it back to the second one). After emptying the first stack, you simply pop from the second stack to complete the dequeue operation.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
