• 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

Data in java please somebody help.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to add comparison and swap, I am freak out, what am I supposed to do? I really dont have any idea, please someone help, I need missing part.

 
Sheriff
Posts: 3061
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi and welcome to JavaRanch!

What you're trying to do is swap values at the j-1 and j positions of the array a. So, if a holds the values: 8 2 1 7 3, and you are comparing the 2 and the 1, then you swap them to get 8 1 2 7 3. Eventually, after enough swapping, the whole array will be sorted (if the rest of your logic is right).

Unfortunately, the way you've written SWAP() there's no way it will work, no matter how the "missing piece" is filled in. That is, whatever you do in the method, the array will be unchanged after you finish. Now, if you defined it like:




then it would be possible to make it work. Give that a try and see if you can figure it out.
 
Bras cause cancer. And tiny ads:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic