Guest User

Untitled

a guest
May 16th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. public class BubbleSort{
  2.  
  3. public String[] bubbleSort(<DataType>[] toSort) {
  4. for (int i = 0; i < toSort.length; i++) {
  5. for (int j = 1; j < toSort.length; j++) {
  6. int compareValue = Character.compare(toSort[j].charAt(0), toSort[j - 1].charAt(0));
  7. if (compareValue == 0) {
  8. int index = 0;
  9. while (compareValue == 0 && index < toSort[j].length() && index < toSort[j - 1].length()) {
  10. compareValue = Character.compare(toSort[j].charAt(index), toSort[j - 1].charAt(index));
  11. index++;
  12. if (compareValue < 1) {
  13. swapValues(toSort, j, j - 1);
  14. }
  15. }
  16.  
  17. } else if (compareValue < 0) {
  18. swapValues(toSort, j, j - 1);
  19. }
  20. }
  21. }
  22. return toSort;
  23. }
  24. }//O(n^2)
Add Comment
Please, Sign In to add comment