You are on page 1of 1

Assignment1 clarification This assignment must be solved using stack which you must implement yourself, along with

its functions push and pop, using an array (you are not allowed to use any other java conatiner classes like vector etc). So a method push(int n) will insert the number n into an array and a method pop() will return the top element of the array. A prototype of these functions would be like public void push(int n) {} public int pop() {} This can then be used to find out whether a permutation is a stack permutation or not. Also, you should print the current stack after every operation that was done to generate the permutation. So now if the input is 5 1 3 5 4 2 [One common confusion among students is to assume that this input is wrong because '5' comes twice in the input. It is to be noted that the number '5' of line 1 denotes the value of 'n' and is different from the number '5' of line 4. Therefore the input is correct.] then output will be Operation print() push(2) print() push(4) print() pop() pop() Stack [] [2] [2] [2,4] [2,4] [2] []

[For a given 'n' the input sequence is always of the form '1,2,3..n', i.e. Increasing ordered sequence from 1 to n. ] Note: 1. Empty stack is same as an empty array. You can reperesent an empty array by all zeros. All other cases of wrong input remain same. The deadline of the assignment has been extended to 28th August, 11:55 pm.

You might also like