Thread: Sorter
View Single Post
Old Jul 29th, 2004, 12:47 AM   #7
ASBands
Newbie
 
Join Date: Jul 2004
Posts: 1
Rep Power: 0 ASBands is on a distinguished road
Bubble Sort all the way!

Just kidding!

But here are two methods for bubble sort with strings...pretty generic...

static void BubbleSortRecurse(String[] s){
 for (int i = 0; i < s.length - 1; i++){
 	if (s[i].compareTo(s[i + 1]) >= 0.0){
  String temp = s[i + 1];
  s[i + 1] = s[i];
  s[i] = temp;

  BubbleSortRecurse(s);
 	}
 }
	}
	
	static void BubbleSortRegular(String[] s){
 for (int i = 0; i < s.length; i++){
 	for (int j = 0; j < s.length - i - 1; j++){
  if (s[j].compareTo(s[j + 1]) >= 0.0){
  	String temp = s[j + 1];
  	s[j + 1] = s[j];
  	s[j] = temp;
  }
 	}
 }
	}
ASBands is offline   Reply With Quote