С как можно меньшим количеством модификаций, почти то же самое в 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;
}
}
}
- некоторые фиктивные занятия (Студент, Информация)
- Узел обычно является общим, а не фиксированным для Student.
- имена классов с заглавными буквами.
- методы и атрибуты просто разделены точкой
- сравнение с CompareTo (для не чисел)
А вот улучшенная версия с типом «Студент» в качестве параметра для узла:
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;
}
}
}
Проблема с неопределенным «началом» унаследована от вас.