#include"iostream.h"
void main()
{
int a[]={3,2,1,-5,-9,5,-8};
int n=sizeof(a);
for(int i=0;i<n;i++)
cout<<*(a+i)<<" ";
cout<<endl;
int k=0,temp;
while(k<n)
{
if(*(a+k))
{
temp=a[n-1];
a[n-1]=a[k];
for(int i=k;i<n-1;i++)
{
a[i]=a[i+1];
}
}
k++;
}
for(int j=0;j<n;j++)
cout<<a[j]<<" ";
}
我的算法 不知道错在哪里
template<class T>
T* partition(T* tStart, T* tEnd)
{
T tX = 0, *tLeft = tStart, *tRight = tEnd;
while (1)
{
while (!(*tRight < tX || tRight == tLeft))
tRight --;
while (*tLeft < tX && tLeft != tRight)
tLeft ++;
if (tLeft < tRight)
swap(*tLeft, *tRight);
else
return tRight;
}
}