Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With as few modifications as possible, nearly the same thing in Java:</p> <pre><code>class Student {String name = "Joe Doe";} class Node { Node next; Student student; } class Info {} public class NodeSorter { Node start; void sort() { Node ctr; Node innerctr; Info temp; Node max; ctr = start; while (ctr != null) { innerctr = ctr.next; max=ctr; while (innerctr != null) { if ((innerctr.student.name).compareTo (max.student.name) &gt; 0) { max = innerctr; } innerctr=innerctr.next; } //swapping... ctr = ctr.next; } } } </code></pre> <ul> <li>some dummy classes (Student, Info)</li> <li>Node would normally be generic, not fixed to Student.</li> <li>classnames with Capitals. </li> <li>methods and attributes are just delimited with dot</li> <li>comparision with compareTo (for non-numbers)</li> </ul> <p>And here is the improved version, with Type "Student" as parameter for the Node: </p> <pre><code>class Student implements Comparable &lt;Student&gt; { String name = "Joe Doe"; public int compareTo (Student other) { if (other == null) return 1; return name.compareTo (other.name); } } class Node &lt;T&gt; { Node &lt;T&gt; next; T value; } class Info {} public class NodeSorter { Node &lt;Comparable&gt; start; void sort () { Node &lt;Comparable&gt; ctr; Node &lt;Comparable&gt; innerctr; Info temp; Node &lt;Comparable&gt; max; ctr = start; while (ctr != null) { innerctr = ctr.next; max=ctr; while (innerctr != null) { if ((innerctr.value).compareTo (max.value) &gt; 0) { max = innerctr; } innerctr=innerctr.next; } //swapping... ctr = ctr.next; } } } </code></pre> <p>The problem with the unspecified 'start' is inherited from you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload