#include <vector> template <class _Ty> void Sort(std::vector<_Ty>& pData,int left,int right) { int i,j; _Ty middle,iTemp; i = left; j = right; middle = pData[(left+right)/2]; do{ while((pData[i]<middle) && (i<right)) i++; while((pData[j]>middle) && (j>left)) j--; if(i<=j) { iTemp = pData[i]; pData[i] = pData[j]; pData[j] = iTemp; i++; j--; } }while(i<=j); if(left<j) Sort(pData,left,j); if(right>i) Sort(pData,i,right); } class Num { public: int i; int mStat; Num(){}; Num(int iI,int bStat) { i=iI; mStat=bStat; }; bool operator>( Num & o) { if (mStat==o.mStat) return i>o.i; else if (mStat==0) return true; else return false; } bool operator<( Num & o) { if (mStat==o.mStat) return i<o.i; else if (mStat==0) return false; else return true; }; }; int main(int argc, char* argv[]) { unsigned char buf[10]={10,2,3,4,5,6,7,8,9,0}; std::vector<unsigned char> vuc(buf, buf + sizeof(buf)); std::vector<Num> a; a.push_back(Num(23,1)); a.push_back(Num(10,0)); a.push_back(Num(15,1)); a.push_back(Num(14,0)); a.push_back(Num(23,0)); a.push_back(Num(41,0)); a.push_back(Num(4 ,0)); Sort(a,3,a.size()-1); for(int i=0;i<a.size();i++) { printf ("%d ",a[i].i); } return 0; }