[Solved] What is the initialising value for top in stacks


It depends upon which implementation of stack you are using(Array, LinkedList). Use can use either top=-1 or top=0 to represent empty stack, no as such hard rule. If you are using an Array based stack(e.g A[n]) then better to use top=-1 as array indexes starts from 0 to n-1 for an array of size n in java.
For 1st push operation, top=-1+1=0, refer to element A[0]

1

solved What is the initialising value for top in stacks