Question: 2. The following program implements a store and retrieve structure which is a cross between a stack and a quue. The retrieve member function retrieves

 2. The following program implements a store and retrieve structure whichis a cross between a stack and a quue. The retrieve member

2. The following program implements a store and retrieve structure which is a cross between a stack and a quue. The retrieve member function retrieves the last node stored (LIFO like a stack) provided the number of nodes stored is odd otherwise it retrieves the first node stored (FIFO like a queue) Write the member functions of the class stacq. Hint: ifx is odd then x % 2 will be 1 For marking purposes store 1, 2, 3, 4 then print to the file, retrieve and print retrieve and print // File: stacq.cpp // This program implements a cross betveen a stack and a queue #include #include using namespace std; class node friend class stacq; private int data; // this is the data in a stacq element node *next; // pointer to the next node on the stack public: node (int x) data-x; next- NULL;) class stacq t private int count; // number of values stored node top; // pointer to the top of the stacq public: stacq (void); void store (int x); int retrieve (void); bool empty(void) const; void write (ostream tout) const; // write stacq to out // constructor of an empty stacq // store the value x // retrieve a value // check for empty stack 1: /*A stacq looks like count | dataI I data I l dataI I data I top l next | next I > l next I > I next I-_-_>NULL int main(void) stacq mine; ofstream fout ("stacqout.txt"); char ch; int x

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!