title: Implementation of stack in C++ without using <stack>
body: <p>I want to make an implementation of stack, I found a working model on the internet, unfortunately it is based on the idea that I know the size of the stack I want to implement right away. What I want to do is be able to add segments to my stack as they are needed, because potential maximum amount of the slots required goes into 10s of thousands and from my understanding making the size set in stone (when all of it is not needed most of the time) is a huge waste of memory and loss of the execution speed of the program. I also do not want to use any complex prewritten functions in my implementation (the functions provided by STL or different libraries such as vector etc.) as I want to understand all of them more by trying to make them myself/with brief help.</p>
  
  <pre><code>        struct variabl {
              char *given_name;
              double value;
          };
          variabl* variables[50000];
          int c = 0;
          int end_of_stack = 0;
  
          class Stack
          {
          private:
              int top, length;
              char *z;
              int index_struc = 0;
  
  
          public:
              Stack(int = 0);
              ~Stack();
              char pop();
              void push();
  
          };
  
          Stack::Stack(int size) /* 
  This is where the problem begins, I want to be able to allocate the size 
        dynamically.
      */
       {
              top = -1;
              length = size;
              z = new char[length];
          }
          void Stack::push()
          {
              ++top;
              z[top] = variables[index_struc]-&gt;value;
              index_struc++;
          }
          char Stack::pop()
          {
              end_of_stack = 0;
              if (z == 0 || top == -1)
              {
                  end_of_stack = 1;
                  return NULL;
              }
              char top_stack = z[top];
              top--;
              length--;
  
              return top_stack;
          }
          Stack::~Stack()
          {
              delete[] z;
          }
  </code></pre>
  
  <p>I had somewhat of a idea, and tried doing </p>
  
  <pre><code>Stack stackk
  //whenever I want to put another thing into stack
  stackk.push = new char;
  </code></pre>
  
  <p>but then I didnt completely understand how will it work for my purpose, I don't think it will be fully accessible with the pop method etc because it will be a set of separate arrays/variables right? I want the implementation to remain reasonably simple so I can understand it.</p>