• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Help counting the number of comparisons in sorting a list.  RSS feed

 
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.

 
Bartender
Posts: 612
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);
 
Sheriff
Posts: 23714
50
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
Posts: 23714
50
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
Boost this thread!