May you please explain what's wrong with my code


i used the inbuilt stack class . but its doesnt showing the right answer . is there something wrong with my approach ??

There is no problem in inbuilt stack. The problem is in the display function
Your i loop in display() is from 0 to primary.size(). But the size of primary stack is changing everytime you are popping an element from it. For example, after enqueueing the 0,1,2,3,4 in the primary stack, you pop 0 and print 0. Then size reduces to 4. Now it’ll print 1 and pop it so the size reduces to 3 (i.e. 2,3,4). Now it will run and pop and print 2 which leaves the primary stack as [3, 4] of size 2 but your i (loop wala) is incremented to 3 which is greater than primary.size(). So it comes out of that loop.
The required change is easy i hope you get it. If not let me know! :slight_smile:

thanx , it’s resolved now