• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

[Solved] bubbleSorting + binary searching from methods .

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 14505
325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do argue you to see Bubble_sort, then your program
 
lowercase baba
Posts: 13082
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
I've read about this kind of thing at the checkout counter. That's where I met this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic