title: Create Stack in C++ with Push, Pop etc
body: <p>We are trying to create a C++ program that works like a stack.
  The following instructions are given:
  There should be several methods:</p>
  
  <p>We have to use this definition of the <code>StackElement</code>:</p>
  
  <pre><code>struct StackElement {
  int digit;
  StackElement* predecessor;
  };
  </code></pre>
  
  <p>The problem now is how to create the <code>push</code>-function without an next parameter as there was with ordinary lists. The same for the pop function.
  We accomplished to get <code>push()</code> create a new StackElement and <code>pop()</code> delete the new Element, but with 2 new Elements, those methods aren't working properly.</p>
  
  <p>Global parameter <code>stack0</code>:</p>
  
  <pre><code>StackElement *stack0 = new StackElement;
  </code></pre>
  
  <p>This is the code for the <code>push</code>-function:</p>
  
  <pre><code>StackElement push(int z){
      StackElement *stack1 = new StackElement;
      stack1-&gt;digit = z;
      stack1-&gt;predecessor = NULL;
      stack0-&gt;predecessor = stack1;
      stack1 = stack0;
  </code></pre>
  
  <p>This is the <code>pop()</code> method:</p>
  
  <pre><code>void pop(){
      StackElement *stack1 = new StackElement;
      if (stack0!=NULL){
      stack1-&gt;digit = 0;
      stack0-&gt;predecessor = NULL; //predecessor = NULL;
      }
  }
  </code></pre>
  
  <p>And finally the <code>main</code> method:</p>
  
  <pre><code>int main()
  {
      int z;
      create();
  
      cout &lt;&lt; "Which number to the stack?" &lt;&lt; endl;
      cin &gt;&gt; z;
  
      push(z);
      pop();
      print();
  
      return 0;
  }
  </code></pre>
  
  <p>We thought about creating a new StackElement, that would work as a 'pseudo'-StackElement and would always stay on top so that the 'real' element on the top would always be the predecessor of the pseudo-Element - but we think this would be against how the stack should work.</p>
  
  <p>So do you guys have any clues on how to proceed? Is there something we are just missing?</p>