to learn data structures and i was at this stack implementation
                  
                  
                  class Stack {
                  
                  
                      int top;
                  
                  
                   
                  
                  
                  public:
                  
                  
                      int a[MAX]; // Maximum size of Stack
                  
                  
                   
                  
                  
                      Stack() { top = -1; }
                  
                  
                      bool push(int x);
                  
                  
                      int pop();
                  
                  
                      int peek();
                  
                  
                      bool isEmpty();
                  
                  
                  };
                  
                  
                  
                  
                  
                  and it says top=-1 , so does it mean Base Address of your Array a + (-1 * size of(data type for array a))
                  
                  
                  
                  
                  
                  but what if that address has a char and not an integer?
                  
                  
                
Nah, the -1 signifies your stack is empty and that's just a convention everyone follows
you have just implemened stack of integers. implement stack of bytes then all types are equal.
Обсуждают сегодня