快速排序结果为什么不正确

int sort(int *a ,int begin ,int end)
{
int low[10] ;
int up[10] ;
int upcnt =0 ;
int lowcnt =0 ;

int c = a[begin] ;//选择第一个元素作为已经排序好的元素

for(int i = begin+1 ;i<=end ;++i)
{
    if(a[i]>=c)
        up[upcnt++] = a[i] ;//大于该该元素的放在up
    else
        low[lowcnt++] = a[i] ;//小于该元素的放于low
}
for(int i =0 ;i< lowcnt ;++i)//写回
{
    a[begin+i] = low[i] ;
}

a[begin+lowcnt] = c ;

for(int i=0 ;i<upcnt ;++i)
{
    a[begin+i+lowcnt+1] = a[i] ;
}


return begin +lowcnt  ;//返回有序元素位置

}

void quicksort(int *a, int begin ,int end)
{

if(begin<end)
{
    int n = sort(a,begin,end) ;

    if(n>begin)
    quicksort(a,begin,n-1) ;

    if(n<end)
    quicksort(a,n+1,end) ;  

}
else
    return ;

}

void main()
{
int a [7] ={10,33,5,63,9,8,1} ;
quicksort(a,0,6) ;

for(int i=0 ;i<6 ;++i)
    cout<<a[i]<<" " ;

}

a[begin+i+lowcnt+1] = a[i] ;
这句应该错了吧

main函数里的输出也不对!才输出了6个.不因该是这样的吗
for(int i=0 ;i<7 ;++i)
cout<<a[i]<<" " ;

找到原因了,sort最后一个循环里面的a[begin+i+lowcnt+1] = a[i] ;应该换成a[begin+i+lowcnt+1] = up[i] ; 看了好多次居然没看出来