64,676
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
using namespace std;
void QuickSort( string & str, string::size_type start, string::size_type end );
int main()
{
string ch("qwertyuiopasdfghjklzxcvbnm");
QuickSort( ch, 0, ch.size() - 1 );
cout << ch << endl;
return 0;
}
void QuickSort( string &str, string::size_type beg, string::size_type end )
{
char middle = str[beg];
string::size_type left = beg;
string::size_type right = end;
while( left != right )
{
while( left != right && str[right] >= middle )
{
--right;
}
str[left] = str[right];
while( left != right && str[left] <= middle )
{
++left;
}
str[right] = str[left];
}
str[left] = middle;
if( beg != left )
{
QuickSort( str, beg, left - 1 );
}
if( right != end )
{
QuickSort( str, right + 1, end );
}
}