1,280 views
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.

1 Answer

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)

Position:
Show:

Related questions

1 1 vote
1 1 answer
2.5k
2.5k views
radha gogia asked Jul 24, 2018
2,478 views
Suppose one character at a time comes as an input from a string of letters . There is an option either to 1) print the incoming letter or to 2) put the incoming letter on...
2 2 votes
1 1 answer
1.9k
1.9k views
Parshu gate asked Nov 11, 2017
1,867 views
Suppose Stack operations are implemented using Queue Operation. Push(x) and Pop() are stack operations whereas enqueue(x) and dequeue are Queue operations.Consider the co...
1 1 vote
1 answers 1 answer
727
727 views
Parshu gate asked Nov 6, 2017
727 views
0 0 votes
2 2 answers
529
529 views