title: Stack (Data structure) implementation
body: <p>So I'm just starting to learn about data structures through a course on Coursera and I learned that it's possible to create a stack data structure by using an array. I was just wondering if what I have written is what a stack is supposed to do. </p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  const int MAX_SIZE = 10000;
  
  class Stack {
      public:
          Stack();
          ~Stack();
          void push(int n);
          void pop();
          int top();
          bool isEmpty() const;
          void print() const;
      private:
          int* array [MAX_SIZE];
          int curNum;
  };
  
  Stack::Stack() {
      curNum = 0;
  }
  
  Stack::~Stack() {
      for (int i = 0; i &lt; curNum; ++i) 
          delete array[i];
  }
  
  void Stack::push(int n) {
      if (curNum &gt;= MAX_SIZE) {
          cout &lt;&lt; "reached maximum capacity...can't add an element\n";
          return;
      }
      array[curNum] = new int(n);
      curNum++;
  }
  
  void Stack::pop() {
      delete array[curNum];
      curNum--;
  }
  
  int Stack::top() {
      return *array[curNum];
  }
  
  void Stack::print() const{
      for (int i = 0; i &lt; curNum; ++i) 
          cout &lt;&lt; *array[i] &lt;&lt; endl;
  }
  
  bool Stack::isEmpty() const{
      return curNum == 0;
  }
  
  int main () {
      Stack stack;
      stack.push(5);
      stack.print();
      stack.pop();
  }
  </code></pre>
  
  <p>Also, I see that a lot of people don't use dynamic memory allocation for this kind of task. Is there a reason why? It seems like specifying a size for the array at compile time might lead to insufficient memory or over-allocating memory to me</p>