2 2 votes Let's consider we have a stack with three operations defined on it:: Push,Pop, Peek We have to print "ABCACBA" using the above operations. Give the min no of operations for doing it and also specify the operations in order. Programming in C data-structures stack + – Tuhin Dutta 1.3k views answer comment Share Follow Print See all 8 Comments 8 8 Comments reply Ashwin Kulkarni commented Dec 9, 2017 reply Follow flag I got 11 operations. push A peek = A push B peek = B push C peek = C push A pop A = A pop = C pop = B pop = A stack is empty. 3 3 replyShare saxena0612 commented Dec 9, 2017 i edited by saxena0612 Dec 9, 2017 reply Follow flag Is it peek or "print"? I am getting 16 of these 3 operations which prints exact string ! 0 0 replyShare Ashwin Kulkarni commented Dec 9, 2017 reply Follow flag Peek is used to simply print topmost element of a stack. Simply I am using logic first push ABC ____ pop CBA but to fill that blank space where A is there I'm pushing and popping that extra A. Is my ans correct? 0 0 replyShare Tuhin Dutta commented Dec 9, 2017 reply Follow flag yes, correct. 0 0 replyShare saxena0612 commented Dec 9, 2017 reply Follow flag @Aswin after you pushed A you are simply popping it not printing it you should print it and then pop it same goes for next operations @ Tuhin what is the given answer is it 11? 0 0 replyShare Ashwin Kulkarni commented Dec 9, 2017 reply Follow flag @saxena0612 Peek and pop both gives output. Only difference is peek doesn't take out top element out of the stack but pop does. 1 1 replyShare saxena0612 commented Dec 9, 2017 reply Follow flag thanks got it now ! 1 1 replyShare sathvikchiramana commented Jul 19, 2018 reply Follow flag @ashwin kulakarni Why are u making stack as empty in the end? 0 0 replyShare Please log in or register to add a comment.
1 1 vote push A→ peek A→push B→peek B→push c→peek C→push A→peek A→pop A→pop C→peek C→pop B→peek B→peek A 14 operations (assuming if it doesn’t matter is stack is empty) and if matters that stack should be empty then 15 operations) rish1602 answered Feb 5, 2021 rish1602 comment Share Follow 0 reply Please log in or register to add a comment.