File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes [Solved] bubbleSorting + binary searching from methods . Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "[Solved] bubbleSorting + binary searching from methods ." Watch "[Solved] bubbleSorting + binary searching from methods ." New topic
Author

[Solved] bubbleSorting + binary searching from methods .

Omar Perez
Ranch Hand

Joined: Jul 08, 2011
Posts: 36
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

Joined: Sep 20, 2010
Posts: 3598
    
  14

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

Joined: Jul 08, 2011
Posts: 36
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

Joined: Jan 28, 2008
Posts: 5575

I do argue you to see Bubble_sort, then your program
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11160
    
  16

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".


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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.


 
Consider Paul's rocket mass heater.
 
subject: [Solved] bubbleSorting + binary searching from methods .
 
Similar Threads
How to print value and the number of times it appear in a array?
incompatable types.
Data in java please somebody help.
String Input and Bubble Sort
Searching an array - output problems - Please help!!