12 May 2005

public embarassment

In the midst of a momentary conniption, I bungled my last post enough to disable its comment function and render the whole thing uneditable, permanently. [and in the meantime, this post seems to have overwritten it!]

A potential commenter alerted me to this fact, while pointing out the apparent oddity that it would take hours to alphabetize less than a million lines. I described my code to this person, who kindly replied:

[acw]: Sorting is so universally useful that there is a sorting utility built into Java. Create an array of strings and pass it to java.util.Arrays.sort(array, 0, length). It returns void, and side-effects the array to put the elements into alphabetical order.

In short, this means I didn't need to write the code to the extent that I did. I'm blushing at the prospect of all the java-savvy blog browsers witnessing my clunky coding skills in such a public venue. And I can't even delete the post! (although, I wouldn't if I could).

I took acw's advice and wrote a new program that sorted my test file in 5 seconds rather than 5 hours. I emailed to thank acw, adding the following observation:

mind you, my old code lets you decide your own alphabetic ordering, and probably could be tweaked to alphabetize from word-ends rather than word beginnings. By the way, I had looked in vain for a sorting utility on the java website, which is why I embarked on making my own bubble-sorter in the first place.

Not that either of those applications is necessarily useful, but they could be if you're working with a language in which characters have a different alphabetic precedence.

0 Comments:

Post a Comment

<< Home