quicksort using stack and partition
here is code   for implementation quicksort using stack and partition,it is taken from  algorithms in c++,third edition(robert sedgewick)

    #include<iostream>
    using namespace std;
    int partition (int a[],int l,int r){
    int i=l-1;
    int j=r;
    int v=a[r];
    for(;;)
    {
    while( a[++i]<v);
    while(v<a[--j]) if(j==i) break;
     if(i>=j) break;
     
     int s=a[i];
     a[i]=a[j];
     a[j]=s;
     
     
     
     
     
    }
     
    
    int m=a[i];
      a[i]=a[r];
      a[r]=m;
     
     
     return i;
    }
     template<class Item>
     class  Stack
     {
     private:
    	 int *s;int N;
     public :
    	 Stack(int maxn)
    	 {
    		 s=new int[maxn];N=0;
    	 }
    	 int empthy() const
    	 {
    		 return N==0;
    
    	 }
    	 void push(int item){
    
    		 s[N++]=item;
    
    	 }
    
    	 int pop(){
    
    		 return s[--N];
    	 }
    	 
     };
    
       inline void  push2(Stack<int>&s,int a,int b){
    	   s.push(a);
    	   s.push(b);
    
    
       }
       void quicksort(int a[],int l,int r){
    	   Stack<int>s(50);
    	   push2(s,l,r);
    	   while(!s.empthy()){
    		   l=s.pop();
    		   r=s.pop();
    		   if(r<=l) continue;
    		   int i=partition(a,l,r);
    
    		   if((i-l)>(r-i))
    		   {    push2(s,l,i-1);push2(s,i+1,r);
    		   }
    		   else{
    
    			   push2(s,i+1,r); push2(s,l,i-1);
    
    		   }
    
    	   }
    
    
       }
    int main(){
    	int a[]={12,32,14,13,15,45,17,16,18,19,20,21};
    	int size=sizeof(a)/sizeof(a[0]);
    	quicksort(a,0,size-1);
    	for(int i=0;i<size;i++)
    		cout<<a[i]<<"  ";
     
    return 0;
    }
but problem is that it does not show me sorted output,just unsorted    result,please give me hint what is error?
quicksort using stack and partition
===

here is code   for implementation quicksort using stack and partition,it is taken from  algorithms in c++,third edition(robert sedgewick)

    #include<iostream>
    using namespace std;
    int partition (int a[],int l,int r){
    int i=l-1;
    int j=r;
    int v=a[r];
    for(;;)
    {
    while( a[++i]<v);
    while(v<a[--j]) if(j==i) break;
     if(i>=j) break;
     
     int s=a[i];
     a[i]=a[j];
     a[j]=s;
     
     
     
     
     
    }
     
    
    int m=a[i];
      a[i]=a[r];
      a[r]=m;
     
     
     return i;
    }
     template<class Item>
     class  Stack
     {
     private:
    	 int *s;int N;
     public :
    	 Stack(int maxn)
    	 {
    		 s=new int[maxn];N=0;
    	 }
    	 int empthy() const
    	 {
    		 return N==0;
    
    	 }
    	 void push(int item){
    
    		 s[N++]=item;
    
    	 }
    
    	 int pop(){
    
    		 return s[--N];
    	 }
    	 
     };
    
       inline void  push2(Stack<int>&s,int a,int b){
    	   s.push(a);
    	   s.push(b);
    
    
       }
       void quicksort(int a[],int l,int r){
    	   Stack<int>s(50);
    	   push2(s,l,r);
    	   while(!s.empthy()){
    		   l=s.pop();
    		   r=s.pop();
    		   if(r<=l) continue;
    		   int i=partition(a,l,r);
    
    		   if((i-l)>(r-i))
    		   {    push2(s,l,i-1);push2(s,i+1,r);
    		   }
    		   else{
    
    			   push2(s,i+1,r); push2(s,l,i-1);
    
    		   }
    
    	   }
    
    
       }
    int main(){
    	int a[]={12,32,14,13,15,45,17,16,18,19,20,21};
    	int size=sizeof(a)/sizeof(a[0]);
    	quicksort(a,0,size-1);
    	for(int i=0;i<size;i++)
    		cout<<a[i]<<"  ";
     
    return 0;
    }
but problem is that it does not show me sorted output,just unsorted    result,please give me hint what is error?