Redirected
443 views
0 votes
0 votes
the o/p of following program is:

queue Q=new queue();

stack S=new stack();

s.push(new interger(8));

s.push(new interger(9));

s.push(new interger(10));

q.enqueue(s.pop());

q.enqueue(new interger(8));

q.enqueue(new intergr(9));

s.push(q.dequeue());

system.out.print(s.pop());

system.out.print(s.pop());

a.10,8,9

b.8,9,10

c.9,8,10

d.10,9,8

my doubt is pf statemnt is 2 so why ans is giving in 3 val??

plx explain last 3 lines.i think in stack the element are 10,9,8 in pop out order(order in which they r pop out)

so ans is D???

1 Answer

Best answer
0 votes
0 votes
Yes U r thinking correct.

This question lacks none of the above option ;p

After doing all above specified operations.

Stack content(bottom to top):-8,9,10

 Queue Content :- 8,9

So then 2 consecutive pop operation will output 10,9 .
selected by

Related questions

2 votes
2 votes
3 answers
1
srestha asked Mar 1, 2019
1,591 views
Runtime stack doesnot contain(A) Local variables(B) Static Variables(C) Parameter Passed(D) Return Address
0 votes
0 votes
1 answer
2
Somdatta Sen asked Feb 9, 2019
399 views
2 votes
2 votes
2 answers
3
0 votes
0 votes
0 answers
4
HeadShot asked Dec 14, 2018
420 views
Please explain points in short, and intuition behind its working.​​