|
某个大包袱总算可以放下了……
放个快排算法安慰自己一下……
[codes=C++]
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin( "qsort.in" );
ofstream fout( "qsort.out" );
long int n = 0;
long int * Set = 0;
void qsort( long int left, long int right )
{
if ( left >= right )
return;
long int i = 0, j = left, k = j;
long int r = right;
long int num = Set[r];
for ( i = left; i < r; i++ )
{
if ( Set > num )
{
swap( Set, Set[j] );
j++;
}
k++;
}
swap( Set[j], Set[r] );
qsort( left, j-1 );
qsort( j+1, right );
}
int main()
{
fin >> n;
Set = new long int [n];
long int i = 0;
for ( i = 0; i < n; i++ )
{
fin >> Set;
}
qsort( 0, n-1 );
for ( i = 0; i < n; i++ )
{
fout << Set << endl;
}
return 0;
}
[/codes]
|
|