• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help counting the number of comparisons in sorting a list.

 
Edward Strife
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

My program needs to generate a list of random integers, the size being entered by the user. Then it needs to sort the list using the Selection Sort algorithm, keeping track of the comparisons made.

I think I have done well so far but for some reason the number of comparisons required are not printing to the screen.

 
Steve Fahlbusch
Bartender
Posts: 602
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just where are you calculating the number of compares?
 
Edward Strife
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
process() keeps track of the number of comparisons (numComparisons) as it sorts the list. This value is returned and used in the statement values = process(size);
 
Paul Clapham
Sheriff
Pie
Posts: 20719
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And perhaps more to the point: where is the code which you think should be displaying the number of comparisons on the screen?
 
Edward Strife
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
values is supposed to be output in the applet in bottomLabel JLabel
 
Paul Clapham
Sheriff
Pie
Posts: 20719
30
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, yes. And are you setting the value of that JLabel before or after you count the comparisons?
 
Edward Strife
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a straightforward way for me to reset the text on that JLabel every time I hit the Enter button?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic