Hmm i just went splitting my code when i realised i cant do that for a recursive function like quicksort.
i would need some further assistance as i was digging into msdn and decided to use threads.
so instead calling recursive function directley i started a new thread with a method that calls quicksort.
basically i didnt change anything just that my function now runs in a separate thread.
the problem is that the function runs only once and refuses to call itself recursiveley.
if anyone can explain to me what is wrong please post here
ill post my code:
so when i call quicksort directley:Code:public static Hashtable bare = new Hashtable(); private bool stopFlag=false; private Thread SThread; ... private void sortThread() { qSort(0,bare.Count-1); } private void qSort(int prim, int ultim) { int i,j; i=prim; j=ultim; Bar baraPivot; baraPivot=((Bar)(bare[(prim+ultim)/2])) ; int pivot = baraPivot.Val; do { while(((Bar)bare[i]).Val <pivot) i++; while(((Bar)(bare[j])).Val >pivot) j--; if (i<=j) { _swapBars(i,j);//function presented in previous post i++;j--; }; }while(i<=j && !stopFlag);//i use stopFlag for //aborting function by user intervention at runtime. if(prim<j && !stopFlag) qSort(prim,j);//quicksort for left partition if(i<ultim && !stopFlag) qSort(i,ultim);//quicksort for right partition }
functions runs smoothley and sorts the elements correctley but when i run it by starting new thread :Code:void BStartClick(object sender, System.EventArgs e) { qSort(0,bare.Count-1); }the function stops after first call (_swapbars is called only once) and ignores recursive calls.Code:void BStartClick(object sender, System.EventArgs e) { SThread = new Thread(new ThreadStart(sortThread)); SThread.Start(); }
is there something i'm missing about threads ? are recursive functions a nono for multithreading ?




Reply With Quote