Consider the following operation performed on a  stack of size 5. 

Push(1); 

Pop(); 

Push(2); 

Push(3); 

Pop(); 

Push(4); 

Pop(); 

Pop(); 

Push(5); 

After the completion of all operation, the number  of elements present in stack are 

(A) 1   (B) 2    (C) 3     (D) 4

 

Slide2.JPG

Slide3.JPG

 


Transcript

Question 1 Consider the following operation performed on a stack of size 5. Push(1); Pop(); Push(2); Push(3); Pop(); Push(4); Pop(); Pop(); Push(5); After the completion of all operation, the number of elements present in stack are (A) 1 (B) 2 (C) 3 (D) 4 push(1) Element 1 is inserted into the empty stack pop( ) Element 1 is deleted from the stack and the stack becomes empty push(2) Element 2 is inserted into the empty stack push(3) Element 3 is inserted into the stack pop( ) Element 3 is deleted from the stack push(4) Element 4 is inserted into the stack pop( ) Element 4 is deleted from the stack pop( ) Element 2 is deleted from the stack and the stack becomes empty push(5) Element 5 is inserted into the stack and the final stack has 1 element

Ask a doubt
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.