made worst case quicksort run nearly impossible by using a random element

git-svn-id: http://svn.osgeo.org/qgis/trunk@279 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
mhugent 2003-09-16 18:21:00 +00:00
parent 78b59e91f2
commit a94e54422a

View File

@ -237,6 +237,10 @@ void QgsAttributeTable::qsort(int lower, int upper, int col, bool ascending, boo
QString v;
if(upper>lower)
{
//chose a random element (this avoids n^2 worst case)
int element=double(rand())/RAND_MAX*(upper-lower)+lower;
swapRows(element,upper);
v=text(upper,col);
i=lower-1;
j=upper;