Question

Question1 ) The STL provides similiar classes called stack and queue, both of which gave functions...

Question1 ) The STL provides similiar classes called stack and queue, both of which gave functions called push and pop. Answer the following questions:
1.1) Does the push perform a different action in the stack class then in the queue class? Explain the answer.

1.2) Does the pop perform a different action in the stack class then in the queue class? Explain the answer.

Question 2)

2.1) Suppose you are tasked with implementing a reverse queue in which elements are enqueued at the front and dequeued at the rear. The implementation is dynamic, and your queue class has Node pointers called front and rear , which point to the front and rear nodes in the queue. The Node struct is given below:

struct Node

{
char element;

Node * next;

};

a) Implement the enqueue function of the reverse queue.

b) Implement the dequeue function of the reverse queue. The function should return the dequeued value.

(Code should be in C++)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.1)   PUSH

YES. Push() function is used to insert an element at the top of the stack as well as in the queue push function is used to insert an element at the back of the queue.

syntax of push in stack : stackname.push(value).

In the above syntax the stackname indicates the name of the stack which is stored and push is the function we are performing and value is the one which value we want to send into the stack.

IN  QUEUE:

push() function is used to insert an element at the back of the queue.when the element is added to the queue the size of the container is increased by 1.

syntax of push in queue: queuename.push(value)

In the above syntax the queuename indicates the name of the queue which is stored and push is the function we are performing and value is the one which value we want to send into the stack.

1.2:)   POP(in stack)

pop() function is used to remove an element from the top of the stack which means the new element which is present in the top of the stack.When an element is removed from the stack the size of the stack is reduced /decreased by 1.

syntax: stackname.pop() . we need to give stackname and pop.

ex:

Input :   mystack = 0,10,33
          mystack.pop();
Output :  0, 10

IN QUEUE :

pop() function is used to remove an element from the front of the queue,which means the old element which is present in the queue is removed using pop in queue.

Input :  myqueue = 30, 20, 40
         myqueue.pop();
Output : 20, 40
Add a comment
Know the answer?
Add Answer to:
Question1 ) The STL provides similiar classes called stack and queue, both of which gave functions...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am to implement a simple simulation that supports a stack and a queue of items being either enqueued and dequeued (ont...

    I am to implement a simple simulation that supports a stack and a queue of items being either enqueued and dequeued (onto the queue) or pushed and popped (onto the stack). I are required to use STL data structures to implement and create the stack and queue for my program. ----- testfile1.tst -------- enqueue 5 enqueue 7 push blooper push rookie dequeue push demerits pop enqueue 3 enqueue 8 push showplace enqueue 9 dequeue pop dequeue push palmetto push zebra...

  • » Part A: Stack Create a Stack struct that is a wrapper for your linked list o You should impleme...

    Using C Please comment » Part A: Stack Create a Stack struct that is a wrapper for your linked list o You should implement the following functions that take a stack o void push(Stack * stack, int value) ● int pop(Stack * stack) Prompt the user to input 5 integers, and use the stack to reverse the integers Print the result to the screen. o o » Part B: Queue o Create a Queue struct that is a wrapper for...

  • e. public class Queue { // Uses the correct Stack class from ME2 Ex 19 private Stack mStack; public Queue() { setStack(new Stack()); } public Queue enqueue(E pData) { getStack().push(pData); return t...

    e. public class Queue { // Uses the correct Stack class from ME2 Ex 19 private Stack mStack; public Queue() { setStack(new Stack()); } public Queue enqueue(E pData) { getStack().push(pData); return this; } public E dequeue() { return getStack().pop(); } public E peek() { return getStack.peek(); } private Stack getStack() { return mStack; } private void setStack(Stack pStack) { mStack = pStack; } } f. public class Queue extends Stack { // Uses the correct Stack class from ME2 Ex...

  • PART A - STACKS To complete this assignment: Please study the code posted below. Please rewrite...

    PART A - STACKS To complete this assignment: Please study the code posted below. Please rewrite the code implementing a template class using a linked list instead of an array. Note: The functionality should remain the same *************************************************************************************************************** /** * Stack implementation using array in C/procedural language. */ #include <iostream> #include <cstdio> #include <cstdlib> //#include <climits> // For INT_MIN #define SIZE 100 using namespace std; /// Create a stack with capacity of 100 elements int stack[SIZE]; /// Initially stack is...

  • HI USING C++ CAN YOU PLEASE PROGRAM THIS ASSIGNMENT AND ADD COMMENTS: stackARRAY: #include<iostream> #define SIZE...

    HI USING C++ CAN YOU PLEASE PROGRAM THIS ASSIGNMENT AND ADD COMMENTS: stackARRAY: #include<iostream> #define SIZE 100 #define NO_ELEMENT -999999 using namespace std; class Stack { int arr[SIZE]; // array to store Stack elements int top; public: Stack() { top = -1; } void push(int); // push an element into Stack int pop(); // pop the top element from Stack int topElement(); // get the top element void display(); // display Stack elements from top to bottom }; void Stack...

  • To solve real world problem, the programer uses ADT like list, stack, queue, set, map, ... etc. t...

    To solve real world problem, the programer uses ADT like list, stack, queue, set, map, ... etc. to build our data model. In AS8, we pick and choose STL queue and stack to build a postfix calculator. In this assignment you are to Design your own linked-list, a series of integer nodes. The private attributes of this IntLinked Queue including a integer node struct and private control variables and methods: private: struct Node { int data; Node *next; }; Node...

  • help finish Queue, don't think I have the right thing. # 1. After studying the Stack...

    help finish Queue, don't think I have the right thing. # 1. After studying the Stack class and testStack() functions in stack.py # complete the Queue class below (and test it with the testQueue function) # # 2. Afer studying and testing the Circle class in circle.py, # complete the Rectangle class below (and test it with the testRectangle function) # # # 3. SUBMIT THIS ONE FILE, with your updates, TO ICON. # # # NOTE: you may certainly...

  • Suppose I want to implement the public member functions of a Stack (push, pop, top, size,...

    Suppose I want to implement the public member functions of a Stack (push, pop, top, size, isEmpty). However, instead of the private member data we had in class, I have only a single Queue. You may assume that the Queue has unbounded capacity, but is otherwise as per the one shown in class. Explain at a high level (you do not need to provide C++ code, but someone should be able to understand how you would code it from what...

  • Study the "Queue as linked list simple example" posted in this module. Rewrite the code to...

    Study the "Queue as linked list simple example" posted in this module. Rewrite the code to use array instead of linked lists. Please do not change anything besides the data structure. Instead of linked list use an array. The functionality should remain exactly the same. LListQueue.cpp ///--------------------------------------------------------------- /// File: LListQueue.cpp /// Purpose: Implementation file for a demonstration of a queue /// implemented as an array. Data type: Character /// Programming Language: C++ ///--------------------------------------------------------------- #include "LListQueue.h" ///-------------------------------------------- /// Function: LListQueue() ///...

  • // =================== Support Code ================= // Queue // // // // - Implement each of the functions to create a working circular queue. // - Do not change any of the function declarations // ...

    // =================== Support Code ================= // Queue // // // // - Implement each of the functions to create a working circular queue. // - Do not change any of the function declarations //   - (i.e. queue_t* create_queue(unsigned int _capacity) should not have additional arguments) // - You should not have any 'printf' statements in your queue functions. //   - (You may consider using these printf statements to debug, but they should be removed from your final version) // ==================================================...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT