Hi, I'm new here, but you'll probably be seeing too much of me before long ;)
My names Daniel.
I have this sort method for sorting (essentially) an array, but it does strange things that i can't quite figure out, and it doesn't sort.
the array is a feature of this class...

class StringCount
String [] _words;
int _wordCount;
int [] _wordPlace;
int [] _wordLength; ....

...which works fine.
and i'm just trying to alphabetically sort the string array, and rearrange the int[]s accordingly.

public static StringCount SCsort(StringCount sortless)
for(int a=0;a+1<sortless.wordCount();a++)
boolean flag = false;
int i, j;
String tempword;
int tempplace;
int templength;
if((sortless.words()[a]).compareTo(sortless.words()[a+1]) > 0)
tempword = sortless.words()[a];
tempplace = sortless.wordPlace()[a];
templength = sortless.wordLength()[a];
sortless.words()[a] = sortless.words()[a+1];
sortless.wordPlace()[a] = sortless.wordPlace()[a+1];
sortless.wordLength()[a] = sortless.wordLength()[a+1];
sortless.words()[a+1] = tempword;
sortless.wordPlace()[a+1] = tempplace;
sortless.wordLength()[a+1] = templength;
return sortless;

I'd appreciate any help here, cos I can't proceed further into the murky waters of my project until i get this working.

Edited by happygeek: fixed formatting

9 Years
Discussion Span
Last Post by FSinister

the for loop gets all the way through itself, i checked it with a print statement.
the couple of unnecessary print statements are there for the same reason. should have removed them.
there's a bit of unnecessary stuff in it cos i've been messing with it and losing my concentration.

the method sorts the first two words, and then i don't know what it does... it edited one of the 633 words somehow.


ok, yes, i'm an idiot. it works now.
i don't have much of an attention span, after a few hours of programming.
sudden down turn in quality of stuff out of me.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.