title: Reverse a Stack using an empty Stack and a variable v
body: <p>I am trying to reverse a stack using an empty stack and a variable v. But I am not getting the answer which I should Get. Can anyone please help me with this ?</p>
  
  <pre><code>void Reverse()
  {
  
      S.push(1);
      S.push(2);
      S.push(3);
  
  
      int v;
      for(int i=1;i&lt;S.size();i++)
      {
  
          v=S.top();
          S.pop();
          for(int j=0;j&lt;S.size()-i;j++ )
          {
              T.push(S.top());
              S.pop();
          }
          S.push(v);
  
          while(!T.empty())
          {
              S.push(T.top());
              T.pop();
          }
  
      }
  }
  </code></pre>