aspose file tools*
The moose likes Beginning Java and the fly likes Bubble Sorting - String Literal Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Bubble Sorting - String Literal" Watch "Bubble Sorting - String Literal" New topic
Author

Bubble Sorting - String Literal

Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349
Does anybody has an example of bubbleSroting the string literal. I succeded to bubble sort the int literal by bubble sort but i need to do that with String.
Please suggest if possible with code.
Thanks very much.
Rashid
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

1) rewrite your existing code to use Integers instead of int (ie use the object wrapper)
2) do all comparison using int1.compare(int2)
3) change methods that you wrote so they accept java.lang.Comparable instead of java.lang.Integers
Now your Bubble sort will sort any object that implements the Comparable interface. Since Strings also inplement this interface, you can handle both object types without having to wrewrite any code.
Is that what we're heading for?
Dave.
Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349
Thanks David for your suggestion but i feel some difficulty to implement your suggestion. In the meanwhile, I made the above program using the compareTo method using String type Arrays.
But the same thing i want to do with String literal without arrays means a para of text which sort out the text in ascending order. I think this would required some further refining. Any suggestion please...

Thanks you very much for quick response.
Best regards
Rashid Ali
 
wood burning stoves
 
subject: Bubble Sorting - String Literal