Here is what I would like you to do. Create a BubbleSortTest class with a main method. Inside main, declare a simple array of type String and initialize it to some text that is not in alpha order. Loop through the array and display the contents. Then call a bubble sort method, and after the call, display the array again. Make the bubble sort method a static method, pattern it after the bblSort3 method in the Week 11 module. You will have to research the text book or the String API to determine which String method should be used to do the comparison for the swapping logic.
Here is what I have done:
public class BubbleSort
{
public static void main(String[] args)
{
String [] mine = {"w","i","e","d","m","o","n","t"};
for (int i = 0; i < 8; i++)
{
System.out.print(mine[i]);
}
public static BubbleSort(String mine[])// error illegal start of expression
{
boolean isSorted;
String tempVar;
int passes = 0;
do
{
isSorted = true;
for (int i = 1; i < mine.length - passes; i++)
{
if (mine[i] < mine[i-1])
{tempVar = mine[i];
mine[i] = mine[i-1];
mine[i-1] = tempVar;
isSorted = false;
}
}
passes++;
while(!isSorted);
return false;
}
}
public int compareToIgnoreCase(String mine)
System.out.println(mine[i]);
System.out.println(false);
}
}

New Topic/Question
Reply




MultiQuote






|