Tuesday, 15 April 2014

java - Sort Array by Alpabetical order using SelectionSort without Array.sort (updated) -


I am referring to my code on the math website on selection coding, accordingly int to < Adding code to my code> string , as well as alphabetical order.

zero selection (student [] cents {int}

SelectionSort for lastName I, j, first; String floating; String jLastName = ""; String firstlatname = ""; String iLastName = ""; For (i = st.length - 1; i>; i--) {first = 0; For (j = 1; j; l; = i; j ++) {if (st [j] .getLastName ()! = Null) {jLastName = st [j] .getLastName (); If (cnt [first] .getLlastName ()! = Null) {firstLastName = st [first] .getLastName (); If ((jLastName.compareToIgnoreCase (firstLastName)) gt; {first = j; }}}} ILastName = st [i] .getLastName (); Temp = firstListName; FirstListName = iLastName; ILastName = temp; }}

The code does not give me the error, however, the output does not show that it has been sorted according to the alphabetical order. Do I know which part I have made a mistake? You use the Compare string as a method:

You do not compare numbers like two strings Can:

  if (st [..]. GetLastName () Compare (..) <0. <..  

its In addition to changing the value, you have a new setter method like the student:

  Public Zero Setlistname (string name) {this.name = name; }  

And then you may like it:

  st [..]. SetName (st [i] .getName ());  

No comments:

Post a Comment