#include <iostream> #define _SZ 10 using namespace std; template<typename _Ty> class Grial { public: Grial(_Ty *_P,int _X=_SZ) { _SP=_X; data = new _Ty[_SP]; for(int _I=0;_I<_SP;_I++) { data[_I]=_P[_I]; } sort(data,0,_SP); } void view() { for(int _I=0;_I<_SP;_I++) { cout<<data[_I]<<" "; } cout<<endl; } private: void sort(_Ty *_A,int _L,int _R) { int _I=_L; int _J=_R-1; if(_L>=_R)return; _Ty temp = _A[_I]; while(_I<_J) { while(_I<_J && _A[_J]>=temp)--_J; _A[_I]=_A[_J]; while(_I<_J && _A[_I]<=temp)++_I; _A[_J]=_A[_I]; } _A[_I]=temp; sort(_A,0,_I-1); sort(_A,_I+1,_R); } private: _Ty *data; int _SP; }; int main() { int a[]={0,4,5,6,7,8,90,5,2,43,2,3,5}; Grial<int> g(a,13); g.view(); return 0; }
时间: 2024-10-29 19:09:39