Nonrecursive quicksort with stack
<p>i am trying to implement quicksort with stack here is code</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
using namespace std;
template&lt;class Item&gt;
class STACK{
private:
    Item *a;int n;
public:
    STACK(int maxN){

        a=new Item[maxN];n=0;

    }
    int empty()const {
        return n==0;

    }
    void push(Item item){
        a[n++]=item;
        }
   Item pop() {
        return a[--n];

   }


};
template&lt;class Item&gt;
int partition (Item a[],int l,int r){

    int i=l-1;
    int j=r;
    Item v=a[r];
     for (;;){

          while (a[++i]&lt;v);
          while (v&lt;a[--j])  if (j==i) break;
           if (i&gt;=j) break;
            Item t=a[i];
            a[i]=a[j];
            a[j]=t;
     }

      Item s=a[i];
       a[i]=a[r];
       a[r]=s;
       return i;
       }
inline void push2(STACK&lt;int&gt;&amp;s,int a,int b){
    s.push(b);
    s.push(a);
    }

template&lt;class Item&gt;
  void quicksort(Item a[],int l,int r){

       STACK&lt;int&gt; s(50);
       push2(a,l,r);
       while (!s.empty()){
           int l=s.pop();
           int r=s.pop();
              if (r&lt;=l) continue;
              int i=partition(a,l,r);
               if(i-1&gt;r-1)
               { push2(a,l,i-1);  push2(a,i+1,r);
               }
               else{
                   push2(a,i+1,r);
                   push2(a,l,i-1);



               }

       }



  }

int main(){

    int a[]={45,12,30,67,11,17,50,78};
    int n=sizeof(a)/sizeof(a[0]);
    quicksort(a,0,n-1);
     for (int i=0;i&lt;n;i++)
         cout&lt;&lt;a[i]&lt;&lt; "  ";




     return 0;

}
</code></pre>

<p>but here is errors</p>

<pre><code>------ Build started: Project: sort_stack, Configuration: Debug Win32 ------
1&gt;  sort_stack.cpp
1&gt;c:\users\david\documents\visual studio 2010\projects\sort_stack\sort_stack.cpp(65): error C2664: 'push2' : cannot convert parameter 1 from 'int []' to 'STACK&lt;Item&gt; &amp;'
1&gt;          with
1&gt;          [
1&gt;              Item=int
1&gt;          ]
1&gt;          c:\users\david\documents\visual studio 2010\projects\sort_stack\sort_stack.cpp(92) : see reference to function template instantiation 'void quicksort&lt;int&gt;(Item [],int,int)' being compiled
1&gt;          with
1&gt;          [
1&gt;              Item=int
1&gt;          ]
1&gt;c:\users\david\documents\visual studio 2010\projects\sort_stack\sort_stack.cpp(72): error C2664: 'push2' : cannot convert parameter 1 from 'int []' to 'STACK&lt;Item&gt; &amp;'
1&gt;          with
1&gt;          [
1&gt;              Item=int
1&gt;          ]
1&gt;c:\users\david\documents\visual studio 2010\projects\sort_stack\sort_stack.cpp(72): error C2664: 'push2' : cannot convert parameter 1 from 'int []' to 'STACK&lt;Item&gt; &amp;'
1&gt;          with
1&gt;          [
1&gt;              Item=int
1&gt;          ]
1&gt;c:\users\david\documents\visual studio 2010\projects\sort_stack\sort_stack.cpp(75): error C2664: 'push2' : cannot convert parameter 1 from 'int []' to 'STACK&lt;Item&gt; &amp;'
1&gt;          with
1&gt;          [
1&gt;              Item=int
1&gt;          ]
1&gt;c:\users\david\documents\visual studio 2010\projects\sort_stack\sort_stack.cpp(76): error C2664: 'push2' : cannot convert parameter 1 from 'int []' to 'STACK&lt;Item&gt; &amp;'
1&gt;          with
1&gt;          [
1&gt;              Item=int
1&gt;          ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
</code></pre>

<p>please help</p>
