Alphabetize A Matrix Of Words
hey, i have a matrix with a different word ( string ) in each cell. I need those to come out in alphabetical order and i cant think of a way how. Any help? Thanks
Example:
Matrix:
{jon,abby,a
,dave,brian,largo};
and i want it to print
"a abby brian dave jon largo"
I dont need to change the matrix, i just need to get the information out in alphabetical order.
> This is part of a really big program that i am not
> using array lists for. Is there any other way to do
> it with matricies or do i have to go back and convert
> everything to arraylists. If thats the case than ill
> just take the hit of some points because thats gonna
> take forever. I am done with the whole program and
> this is the only thing left to do.
You don't have to change the matrices, you're just using the ArrayList to do the sorting for you. Step 1 was copying the values from the matrix into the List; the matrix is unchanged. If all you want to do is print them out alphabatized, then trash the List afterwards. If you want to keep them in sorted order, then hang onto the List. If you want to put them back into the matrix in sorted order, then you'll have to decide how to do that.
> So you are disallowed using ArrayList or any
> additional Class, not yet used? In that case, it will
> be difficult to sort easily or efficiently.
If it's part of your assignment that you can't use the classes we've suggested, and have to implement the sorting yourself, then the String class has a built in comparitor method you can use. Look up sorting algorithms and then apply the compareTo method to do the comparisons.