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;
for(i=0;i<sortless.wordCount()-1;i++)
{
for(j=i+1;j<sortless.wordCount();j++)
{
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;
System.out.println(tempword);
flag=true;
}
}
}
}
System.out.println(sortless.wordCount());
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.

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.
anyway.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.