Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[Solved] bubbleSorting + binary searching from methods .

 
Omar Perez
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all folks for all the solutions and proposals, really appreciated.

This the code (done in three classes).

First the bubble sort code an Algorithm for sorting values, in this from min to max;


The bubble code was for a binary search, this is the code for binary search (iterative way);



No you guys are in charge of working the main class. Thank you all for your collaboration.
 
Stephan van Hulst
Bartender
Pie
Posts: 5898
63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Omar,

I haven't looked at your code very carefully, but it looks like you're doing something dangerous on line 43: maybe you should use the == operator instead of the = operator.
 
Omar Perez
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:Hi Omar,

I haven't looked at your code very carefully, but it looks like you're doing something dangerous on line 43: maybe you should use the == operator instead of the = operator.


fixed, I got the exception fixed, now having issues with method not returning all values sorted.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do argue you to see Bubble_sort, then your program
 
fred rosenberger
lowercase baba
Bartender
Posts: 12146
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is returning one number because you are telling it to:

return array[9];

says "return the element of the array at index position 9" and NOT "return an array with 9 elements".
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Omar Perez wrote:
Stephan van Hulst wrote:Hi Omar,

I haven't looked at your code very carefully, but it looks like you're doing something dangerous on line 43: maybe you should use the == operator instead of the = operator.


fixed, I got the exception fixed, now having issues with method not returning all values sorted.


Better yet get rid of the == altogether.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic