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 Data in java please somebody help. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Data in java please somebody help." Watch "Data in java please somebody help." New topic
Author

Data in java please somebody help.

baran yildirim
Greenhorn

Joined: Oct 09, 2012
Posts: 1
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.

Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2833
    
  11

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Data in java please somebody help.
 
Similar Threads
Swapping of Object in Java
Find two repeating elements in an Array
Sorting array on command line
String Input and Bubble Sort
Help me with BubbleSort