With as few modifications as possible, nearly the same thing in Java:
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) > 0)
{
max = innerctr;
}
innerctr=innerctr.next;
}
//swapping...
ctr = ctr.next;
}
}
}
- some dummy classes (Student, Info)
- Node would normally be generic, not fixed to Student.
- classnames with Capitals.
- methods and attributes are just delimited with dot
- comparision with compareTo (for non-numbers)
And here is the improved version, with Type "Student" as parameter for the Node:
class Student implements Comparable <Student> {
String name = "Joe Doe";
public int compareTo (Student other) {
if (other == null) return 1;
return name.compareTo (other.name);
}
}
class Node <T> {
Node <T> next;
T value;
}
class Info {}
public class NodeSorter {
Node <Comparable> start;
void sort ()
{
Node <Comparable> ctr;
Node <Comparable> innerctr;
Info temp;
Node <Comparable> max;
ctr = start;
while (ctr != null)
{
innerctr = ctr.next;
max=ctr;
while (innerctr != null)
{
if ((innerctr.value).compareTo (max.value) > 0)
{
max = innerctr;
}
innerctr=innerctr.next;
}
//swapping...
ctr = ctr.next;
}
}
}
The problem with the unspecified 'start' is inherited from you.