c) Suppose you have three stacks sl, s2, s2 with starting configuration shown on the left, and finishing condition shown on the right. Give a sequence of push and pop operations that take you from start to finish. For example, to pop the top element of s1 and push it onto s3, you would write s3.push( s1.pop()). start finish A C A D --- s1 s2 s3 s1 s2 s3 d) In implementing a Queue using an array, a problem might arise if the Queue is implemented in such a way that items in the Queue are inserted at the next available location and removed from the next leading position, but such that, once deleted, the emptied space is unused. The problem that arises is one where there is free space still in the array, but it is not useable because it is not at the end. Demonstrate this problem with a Queue that is stored in an array of size 5 for the following instructions. Next, explain how you might resolve this problem. B.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 3PE
icon
Related questions
Question
1. a)
Convert (A+B* (C-D))/E into Postfix from showing stack status after every step in tabular
form.
1.
b)
Consider the following stack of characters, where STACK is allocated N = 5 memory cells
4
STACK :
3
2
1
A
Describe the stack as the following operations takes place:
(i)
(ii)
(ii)
POP(STACK,ITEM)
PUSH(STACK, C)
POP(STACK, ITEM)
PUSH(STACK, D)
PUSH(STACK, E)
POP(STACK, ITEM)
(v)
(vi)
Transcribed Image Text:1. a) Convert (A+B* (C-D))/E into Postfix from showing stack status after every step in tabular form. 1. b) Consider the following stack of characters, where STACK is allocated N = 5 memory cells 4 STACK : 3 2 1 A Describe the stack as the following operations takes place: (i) (ii) (ii) POP(STACK,ITEM) PUSH(STACK, C) POP(STACK, ITEM) PUSH(STACK, D) PUSH(STACK, E) POP(STACK, ITEM) (v) (vi)
c) Suppose you have three stacks sl, s2, s2 with starting configuration shown on the left, and
finishing condition shown on the right. Give a sequence of push and pop operations that
take you from start to finish. For example, to pop the top element of s1 and push it onto
s3, you would write s3.push( s1.pop()).
start
finish
A
B
A
D
D
E
E
---
.--
s1
s2
s3
s1
s2
s3
d) In implementing a Queue using an array, a problem might arise if the Queue is implemented in such a
way that items in the Queue are inserted at the next available location and removed from the next leading
position, but such that, once deleted, the emptied space is unused. The problem that arises is one where
there is free space still in the array, but it is not useable because it is not at the end. Demonstrate this
problem with a Queue that is stored in an array of size 5 for the following instructions. Next, explain how
you might resolve this problem.
Queue q = new Queue(4); // assume the Queue constructor takes 5 as the size of the array
q.enqueue(7):
q.enqueue (13);
q.dequeue ( );
q.enqueue(16);
q.dequeue();
q.enqueue(11);
q.dequeue( );
q.enqueue(15);
q.dequeue( );
B.
Transcribed Image Text:c) Suppose you have three stacks sl, s2, s2 with starting configuration shown on the left, and finishing condition shown on the right. Give a sequence of push and pop operations that take you from start to finish. For example, to pop the top element of s1 and push it onto s3, you would write s3.push( s1.pop()). start finish A B A D D E E --- .-- s1 s2 s3 s1 s2 s3 d) In implementing a Queue using an array, a problem might arise if the Queue is implemented in such a way that items in the Queue are inserted at the next available location and removed from the next leading position, but such that, once deleted, the emptied space is unused. The problem that arises is one where there is free space still in the array, but it is not useable because it is not at the end. Demonstrate this problem with a Queue that is stored in an array of size 5 for the following instructions. Next, explain how you might resolve this problem. Queue q = new Queue(4); // assume the Queue constructor takes 5 as the size of the array q.enqueue(7): q.enqueue (13); q.dequeue ( ); q.enqueue(16); q.dequeue(); q.enqueue(11); q.dequeue( ); q.enqueue(15); q.dequeue( ); B.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Stack
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning