recategorized by
33,090 views
33 votes
33 votes

Which of the following permutations can be obtained in the output (in the same order) using a stack assuming that the input is the sequence $\text{1, 2, 3, 4, 5}$ in that order?

  1. $\text{3, 4, 5, 1, 2}$
  2. $\text{3, 4, 5, 2, 1}$
  3. $\text{1, 5, 2, 3, 4}$
  4. $\text{5, 4, 3, 1, 2}$
recategorized by

6 Answers

1 votes
1 votes
Push 1

Push 2

Push 3

Pop 3. (3)

Push 4

Pop 4. (4)

Push 5

Pop 5. (5)

Pop 2. (2)

Pop 1 .(1)

Soo the order is 3,4,5,2,1
0 votes
0 votes
we can do it inspection very easily,how it can be efficiently using programming ?
Answer:

Related questions

35 votes
35 votes
4 answers
2
Kathleen asked Oct 4, 2014
22,916 views
Linked lists are not suitable data structures for which one of the following problems?Insertion sortBinary searchRadix sortPolynomial manipulation
29 votes
29 votes
6 answers
4
Kathleen asked Oct 5, 2014
4,886 views
An array $A$ contains $n$ integers in non-decreasing order, $A \leq A \leq \cdots \leq A[n]$. Describe, using Pascal like pseudo code, a linear time algorithm to find $...