Display how sort works? Please help

Reply

Join Date: Jan 2008
Posts: 25
Reputation: Alishaikh is an unknown quantity at this point 
Solved Threads: 0
Alishaikh Alishaikh is offline Offline
Light Poster

Display how sort works? Please help

 
0
  #1
Jan 4th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 25
Reputation: Alishaikh is an unknown quantity at this point 
Solved Threads: 0
Alishaikh Alishaikh is offline Offline
Light Poster

Re: Display how sort works? Please help

 
0
  #2
Jan 4th, 2009
I didn't post the file sorry. It is attached below. Do I have to make changes to this program? or can I write a driver one?
Attached Files
File Type: java Sorts.java (2.8 KB, 5 views)
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 822
Reputation: verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough 
Solved Threads: 73
verruckt24's Avatar
verruckt24 verruckt24 is offline Offline
Practically a Posting Shark

Re: Display how sort works? Please help

 
0
  #3
Jan 5th, 2009
Would you mind putting your code directly here in code tags ?
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,625
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 221
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is online now Online
Posting Virtuoso

Re: Display how sort works? Please help

 
0
  #4
Jan 5th, 2009
Originally Posted by Alishaikh View Post
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 in bars.

What is this bars?
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 6
Reputation: hypocrisy is an unknown quantity at this point 
Solved Threads: 1
hypocrisy hypocrisy is offline Offline
Newbie Poster

Re: Display how sort works? Please help

 
0
  #5
Jan 7th, 2009
hii
try to make your question more clear until we can help you with your problem.
good luck
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 25
Reputation: Alishaikh is an unknown quantity at this point 
Solved Threads: 0
Alishaikh Alishaikh is offline Offline
Light Poster

Re: Display how sort works? Please help

 
0
  #6
Jan 7th, 2009
Well I have to show the sort go through the array. Like every time it goes through the array, in an applet
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,625
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 221
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is online now Online
Posting Virtuoso

Re: Display how sort works? Please help

 
0
  #7
Jan 8th, 2009
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
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 25
Reputation: Alishaikh is an unknown quantity at this point 
Solved Threads: 0
Alishaikh Alishaikh is offline Offline
Light Poster

Re: Display how sort works? Please help

 
0
  #8
Jan 8th, 2009
No no, I wrote the sorts in an earlier program. But I cant get it to print after every loop. This is what I have so far(I decided to forgo the applet, and do this first, and its due within the next hour. I'm in school right now)
BUT it wont work at all....PLease help
Attached Files
File Type: java Array.java (458 Bytes, 1 views)
File Type: java Sorts.java (3.1 KB, 3 views)
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,625
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 221
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is online now Online
Posting Virtuoso

Re: Display how sort works? Please help

 
0
  #9
Jan 8th, 2009
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:
  1. for (int scan = index+1; scan < numbers.length; scan++){
  2. if (numbers[scan] < numbers[min])
  3. min = scan;
  4. for(int i=0;i<numbers.length;i++) {
  5. System.out.print(numbers[i]+", ");
  6. }
  7. System.out.println();
  8. }
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 25
Reputation: Alishaikh is an unknown quantity at this point 
Solved Threads: 0
Alishaikh Alishaikh is offline Offline
Light Poster

Re: Display how sort works? Please help

 
0
  #10
Jan 8th, 2009
I made new code!!! This is an applet, but I dont know how to keep displaying the bars after each loop. PLease tell me how I can do that.
  1. /**
  2.  * @(#)SelectionBars.java
  3.  *
  4.  * SelectionBars Applet application
  5.  *
  6.  * @author
  7.  * @version 1.00 2009/1/8
  8.  */
  9.  
  10. import java.awt.event.*;
  11. import java.util.Random;
  12. import javax.swing.*;
  13. import java.awt.*;
  14. import java.applet.*;
  15.  
  16. public class SelectionBars extends Applet {
  17. //Variables and arrays
  18. Rectangle[] bar_array = new Rectangle[10];
  19. int minIndex;
  20. public void init() {
  21. final int NUM_BARS = 10, WIDTH = 30, MAX_HEIGHT = 300, GAP = 9;
  22. int x = GAP, height;
  23. bar_array = new Rectangle[10];
  24.  
  25. Random generator = new Random();
  26. height = generator.nextInt(MAX_HEIGHT) + 1;
  27.  
  28. for (int i = 0; i < NUM_BARS; i++)
  29. {
  30. bar_array[i] = new Rectangle(x, MAX_HEIGHT-height, WIDTH, height);
  31. height = generator.nextInt(MAX_HEIGHT) + 1;
  32. x = x + WIDTH + GAP;
  33. }
  34.  
  35. }
  36. void selectionSort()
  37. {
  38. for( int i = 0; i < bar_array.length - 1; i++ )
  39. {
  40. int minIndex = i;
  41. for( int j = i + 1; j < bar_array.length; j++ )
  42. {
  43. if( bar_array[j].height < bar_array[minIndex].height )
  44. {
  45. minIndex = j;
  46. }
  47. }
  48.  
  49. if(minIndex > i)
  50. {
  51. Rectangle temp = bar_array[i];
  52. bar_array[i] = bar_array[minIndex];
  53. bar_array[minIndex] = temp;
  54.  
  55. int tempX = bar_array[i].x;
  56. bar_array[i].x = bar_array[minIndex].x;
  57. bar_array[minIndex].x = tempX;
  58. }
  59. }
  60. }
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. public void paint (Graphics page)
  70. {
  71. final int GAP = 9;
  72. int x;
  73. setBackground (Color.black);
  74.  
  75. page.setColor (Color.blue);
  76. x = GAP;
  77.  
  78. for (int i = 0; i < bar_array.length; i++)
  79. {
  80. Dimension d = bar_array[i].getSize();
  81. Point p = bar_array[i].getLocation();
  82. page.fillRect(p.x, p.y, d.width, d.height);
  83.  
  84. x = x + WIDTH + GAP;
  85. }
  86.  
  87. }
  88.  
  89. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC