Hello,
I was wondering why do we need to assign value of -1 to the top of the stack?
topOfStack = -1;
Thank you
grisha83 26 Junior Poster in Training
Recommended Answers
Jump to PostThe top of the stack is -1 when the stack is empty. When you fill it using push(), the top will change. A return value of -1 lets the user know that the stack is empty.
Jump to PostAs hardik.rajani mentions there's is little programming "tradition" to this.
The concept of the Top of Stack is that the Top should always point to the uppermost/topmost element in the Stack.
Now to follow this concept, it would be a logical thing that you first need to increment …
All 5 Replies
Grn Xtrm 84 Posting Pro in Training
Mubo 0 Newbie Poster
hardik.rajani 0 Light Poster
verruckt24 438 Posting Shark
grisha83 26 Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.