1

I'd like to have the list be in ascending order via "sortAscending" and then send "showArray" and "sortAscending" to a textfile. "sortAscending(list);" isn't showing anything when running it, and there are no syntax errors.

sortAscending(list);
public static String[] sortAscending(String[] names)
{
    String temp;
    int passNum, i, result;
    for(passNum=1; passNum < 10; passNum++)
    {
        for(i = 0; i<(10-passNum); i++)
        {
            result=names[i].compareToIgnoreCase(names[i+1]);
            if(result>0)
            {
                temp=names[i];
                names[i]=names[i+1];
                names[i+1]=temp;
            }
        }
    }
    return names;
2
  • What do you mean by "send showArray and sortAscending to a text file"? Do you mean "write the current order of the list to the text file"? Commented Oct 7, 2014 at 3:18
  • Is sorting a part of assignment? If not then instead of using Bubble Sort, either try using some good algorithm like Quicksort, or else use an inbuilt function from java.util package, Arrays.sort(array);. Commented Oct 7, 2014 at 3:38

1 Answer 1

2
// Print sorted list 
sortAscending(list);

sortAscending is not printing anything. It just sorts the list. You probably want to

// Sort the list and print it
showArray(sortAscending(list));
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! Any advice how I can send unsorted and sorted data to "output.txt"? I can only get it to send the sorted data.
That's because your sort function destroys the original array. Output it before sorting or make a copy of the array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.