• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bubble Sorting - String Literal

 
Rashid Ali
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic