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 Posthi dear, let me try to say some about you question.
I think ur question is why stacks are assigned -1 when determining if they are empty();
i think , it is because the index position of -1 is the empty position of the stack. they follow the integer …
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.