Question: Please use c++ and make sure to test the stack in the main function. Thanks 5. Write a stack class using two STL lists. Naturally,

Please use c++ and make sure to test the stack in the main function. Thanks

Please use c++ and make sure to test the stack in the

5. Write a stack class using two STL lists. Naturally, a single STL list is more than enough to represent a stack. However, you are only limited to the following STL list methods (a) void push back(const Object & x); //adds x to the end of list (b) void pop front); //removes the object at the front of the list (c) Object & front); //returns the object at the front of the list (d) bool empty() const; //true if empty container Limited to these methods alone, our STL list essentially becomes a queue (enqueue is basically push back while dequeue is a combination of front and pop_front). At the minimum, your stack class needs to have the followinjg (a) An STL list is stored as an instance member of the stack class. You can think of this main list as storing your stack. (b) A pop method that returns an Object at the top of the stack. (c) A push method that takes an Object and places it at the top of the stack (d) If your list is empty, your pop method should throw an exception (any exception will do) (e) Inside your push method, you can create a temporary list. As you are only limited to placing items at the back of your list (enqueue / push back), you can use this temporary list as storage to help move items from your main list to this list, add the new item to your main list, and then move back the items from the temporary list back to your main list

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!