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
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
ADVERTISEMENT