title: how to reverse a stack
body: <p>I have an assignment where I am suppose to take a single stack, show the output and then reverse it to show the output. </p>
  
  <p><strong>Its suppose to look like this</strong></p>
  
  <pre><code>Stack:
  262 115 74 26 34 243 22 734 113 121
  Stack Reversed:
  121 113 734 22 243 34 26 74 115 262
  </code></pre>
  
  <p><strong>Instead mine is coming out like this</strong></p>
  
  <pre><code>Stack:
  262 115 74 26 34 243 22 734 113 121 121 113 734 22 243 34 26 74 115 262
  Stack Reversed:
  </code></pre>
  
  <p>Can someone please look at my code and see what is going on. I have tried quite a few things but cannot get anything to work. </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;iostream&gt;
  
  #include "linkedStack.h"
  
  using namespace std;
  
  template &lt;class Type&gt;
  void printStack(linkedStackType&lt;Type&gt;&amp; stack);
  
  template &lt;class Type&gt;
  void reverseStack(linkedStackType&lt;Type&gt;&amp; stack);
  
  int main(int argc, char **argv)
  {
     // Declare stack variables
     linkedStackType&lt;int&gt; stack;
  
     // Add some data to the stack
     stack.push(121);
     stack.push(113);
     stack.push(734);
     stack.push(22);
     stack.push(243);
     stack.push(34);
     stack.push(26);
     stack.push(74);
     stack.push(115);
     stack.push(262);
  
     cout &lt;&lt; "\nStack:\n   ";
     printStack(stack);
  
     reverseStack(stack);
  
     cout &lt;&lt; "\nStack Reversed:\n   ";
     printStack(stack);
  
     cout &lt;&lt; "\n\n** Press any key to continue **\n";
     getchar();
  
     return 0;
  }
  
  template &lt;class Type&gt;
  void printStack(linkedStackType&lt;Type&gt;&amp; stack)
  {
     Type item;
     linkedStackType&lt;Type&gt; tmpStack = stack;
  
     while (stack.isEmptyStack() == false)
     {
        item = stack.top();
        stack.pop();
        cout &lt;&lt; item &lt;&lt; " ";
     }
  
     stack = tmpStack;
  
  
  
   }
  
  template &lt;class Type&gt;
  void reverseStack(linkedStackType&lt;Type&gt;&amp; stack)
  {
    Type item;
     linkedStackType&lt;Type&gt; tmpStack;
  
     while (stack.isEmptyStack() == false)
     {
        item = stack.top();
        stack.pop();
        tmpStack.push(item);
     }
  
     while (tmpStack.isEmptyStack() == false)
     {
        item = tmpStack.top();
        tmpStack.pop();
        stack.push(item);
        cout &lt;&lt; item;  
  
     }
  
     stack = tmpStack;
  
  
     return;
  }
  </code></pre>