From a94e54422a100830dd67d55fe4e8f699d14ffd4d Mon Sep 17 00:00:00 2001 From: mhugent Date: Tue, 16 Sep 2003 18:21:00 +0000 Subject: [PATCH] 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 --- src/qgsattributetable.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/qgsattributetable.cpp b/src/qgsattributetable.cpp index c876bc36d75..70158e788cd 100644 --- a/src/qgsattributetable.cpp +++ b/src/qgsattributetable.cpp @@ -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;