I have attached the file with the sorts. I have to show 2 sorts insertion, and selection sorts demonstration in bars. I should show the position of the bars after each run. How do i go on about doing that?
What do you mean when you say:
I have to show 2 sorts insertion, and selection sorts demonstration inbars.
What is this bars?
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
You can create an array with some numbers inside.
>Then print its values,
>Call the sort method
>Print again the values.
Also if you want to see how the sort progresses you can change the methods given and add some :
>System.out.printlns after each loop is run.
Every time a loop of the method is executed print the values. (You will need another for-loop) to print the values.
As for applets have a textarea where you print the values of the array in each line. Check the API for the JTextArea class. Also you probably have some notes on how to create an applet.
What I can't understand is why you where given the code ready and asked to do it in applet. Usually applets are more "advanced" than a simple sort method. How can your teacher expect you to write an applet when you haven't even learned the simple sort algorithms since he is handing them to you ?
I believe that you should first learn how to write these sort algorithms before being asked to do them in applets
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
You don't say what doesn't work and what errors you get.
Also it would be a good idea to print the values in 1 line:
for (int scan = index+1; scan < numbers.length; scan++){
if (numbers[scan] < numbers[min])
min = scan;
for(int i=0;i<numbers.length;i++) {
System.out.print(numbers[i]+", ");
}
System.out.println();
}
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
Applets are not my strong point.
But I advised you to use a JTextArea and display in each line the elements of the array.
Check the API of JTextArea on how to append and set text
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
But I dont need text. I just need to know how to use the sort in the applet
If you want to use it, just call it and sort an array.
But how would you show to the GUI the results? Aren't you supposed to print them somewhere?
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448