天天看點

C++ Stack Implementation Discussion

1. Q:  Why Stack::top is initialized to -1 ?

A: Initialize top = -1 make push(char x){ item[++top] = x} method consistent with the API design that stack::top refers to the top element in the stack