I'm not really sure how to proceed. I just am looking for a "start here" launch pad to sort a string array and then if something is moved- move the other three arrays accordingly. The examples of selection sort that I've seen and been provided use int and double; I get that. Doing it with a string is mind boggling to say the least.
Task: selection sort using four parallel arrays.
Page 1 of 14 Replies - 1457 Views - Last Post: 19 April 2011 - 10:03 PM
Replies To: Task: selection sort using four parallel arrays.
#2
Re: Task: selection sort using four parallel arrays.
Posted 19 April 2011 - 09:52 PM
Use objects, not parallel arrays, macosxnerd101 has a tutorial on that in the java tutorial section: Moving away from parallel arrays
This post has been edited by TFoSSDQ: 19 April 2011 - 09:53 PM
#3
Re: Task: selection sort using four parallel arrays.
Posted 19 April 2011 - 09:54 PM
Take a look at the documentation for the String class. Strings are compared using the compareTo() method rather than the <, <=, >, and >= operators.
As an example:
If compare < 0, then s < "234" so to speak. If compare == 0, then the two Strings are equal. Otherwise, s > "234" so to speak.
If you have to use parallel arrays, those are the constraints of your assignment. But as you get more into programming, you should really consider using classes and Objects instead. It is a more standards way of doing things.
As an example:
String s = "123";
int compare = s.compareTo("234");
If compare < 0, then s < "234" so to speak. If compare == 0, then the two Strings are equal. Otherwise, s > "234" so to speak.
If you have to use parallel arrays, those are the constraints of your assignment. But as you get more into programming, you should really consider using classes and Objects instead. It is a more standards way of doing things.
#4
Re: Task: selection sort using four parallel arrays.
Posted 19 April 2011 - 09:55 PM
Here is a code snippet by mostyfriedman demonstrating how to implement a selection sort in Java.
Start with what he has already written and figure out how you can apply this to arrays.
Start with what he has already written and figure out how you can apply this to arrays.
#5
Re: Task: selection sort using four parallel arrays.
Posted 19 April 2011 - 10:03 PM
Thanks for the tips guys.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote






|