+ 1

Stack implementation using array

Why n value decrement during push operation in this code https://code.sololearn.com/cFRuIrU3Xz9G/?ref=app

21st Sep 2023, 10:30 AM
Pravin
Pravin - avatar
1 Odpowiedź
+ 4
n never decreasing. top is increasing.. n is size of array so n-1 is the last possible location to add element. So you can't add at next location, top++ results overflow so it print stack over"flow"...
21st Sep 2023, 11:07 AM
Jayakrishna 🇮🇳