Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to implement runnable to my quicksort algorithm

807600Nov 5 2007 — edited Nov 5 2007
Hello guys,
i am stuck with this problem
i have a program quicksort and i want to draw graphics how the quicksort works, but here is a problem
how can i call thread method run() to to only a few steps of quicksort then repaint a graph, then quicksort then repaint..etc

here is my code for quicksorth algorithm i need to implement method run and in other class for example Painter
to use paint method to draw this graph, but step after step
public class QuickSort implements Runnable{
	
  public void sort (int[] vstupnePole) {
	  QSort(vstupnePole,0,vstupnePole.length-1);  
  }
  
 
	public void QSort(int[] array,int zac,int kon){	
		int i = zac;
		int j = kon;
		int pivot = array[(i+j)/2];
		while(i<=j){
			
			while(pivot<array[j]){j--;}  
			while(pivot>array){i++;}

if (i<=j){
int temp = array[i];
array[i] = array[j];
array[j] = temp;
i++;
j--;
}
}
if (zac<j){QSort(array,zac,j);}
if (i<kon){QSort(array,i,kon);}
}
}
i need to use thread.sleep() to have a few sec to paint my graph and then quicksort must continue,
how can i do this ?     I am beginner with java threads (i can use them in a simple cycle not in a recursive method) 

thanks in advance;)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 3 2007
Added on Nov 5 2007
5 comments
367 views