title: Function that will leave the smallest occurrences at the bottom of stack
body: <p>I am trying to write a stack so that all of the occurrences of the smallest element are at the bottom of the stack, while the order of the other elements stays the same. For example, if I have the stack [4,3,1,5,8,1,4] it will become [4,3,5,8,4,1,1], but my problem is that the order changes
  so i will get something like this[4,5,3,4,8,1,1]</p>
  
  <pre><code> #include &lt;iostream&gt;
  #include &lt;stack&gt;
  using namespace std;
  
  void minstack(stack&lt;int&gt; &amp;s)
  {
  
  stack&lt;int&gt; t1,t2;
  int count=0,min;
  if(!s.empty())
      {
  
        while(!s.empty())
        {
            if(s.top() &lt;min)
              { min=s.top();
                  count=0;
                  }
  
            t1.push(s.top()); s.pop();
            count++; 
        }
  for(int i = 0 ; i&lt;count;i++)
  
  {
      s.push(min);
  }
  
   while(!t1.empty())
        {
            if(t1.top()!=min);
            { s.push(t1.top());
                }
            t1.pop();
        }
  }
  }
  int main()
  {
      stack &lt;int&gt; s;
      s.push(4);
          s.push(3);
      s.push(1);
      s.push(5);
      s.push(8);
      s.push(1);
          s.push(4);
  minstack(s);
  while(!s.empty())
  {
      cout&lt;&lt;s.top()&lt;&lt;" "; s.pop();
  }
  
  }
  </code></pre>