如何在LinkedList中获得两个值



我在链表中有三个变量(以StudentID, Group, Priority为例)

我在程序中使用了以下代码:

public String toString() {
System.out.println("--------------------------------------");
String str = " ";
ListNode current = head;
while (current != null) {
str += "StudentID: " + StudentAdd.getStudentID() + " is in Group " +
StudentAdd.getGroup().toUpperCase() + " with priority " + 
StudentAdd.getPriority();
str += "]n";
current = current.getNext();
}

return str;
}

我想得到以下输出

[StudentID:0001 is in Group A with Priority 1]
[StudentID:0005 is in Group C with Priority 1]
[StudentID:0220 is in Group B with Priority 2]
[StudentID:0200 is in Group B with Priority 2]
[StudentID:0215 is in Group B with Priority 2]
[StudentID:0315 is in Group B with Priority 3]
[StudentID:0301 is in Group B with Priority 3]
[StudentID:0350 is in Group B with Priority 3]
但是,I只得到以下输出
[StudentID:0350 is in Group B with Priority 3]
[StudentID:0350 is in Group B with Priority 3]
[StudentID:0350 is in Group B with Priority 3]
[StudentID:0350 is in Group B with Priority 3]
[StudentID:0350 is in Group B with Priority 3]
[StudentID:0350 is in Group B with Priority 3]
[StudentID:0350 is in Group B with Priority 3]
[StudentID:0350 is in Group B with Priority 3]

显示学生的最后一次输入

那么我如何更新它呢?

reference "current"节点,而不是"StudentAdd",像下面的

while (current != null) {
str += "StudentID: " + current.getStudentID() + " is in Group " +
current.getGroup().toUpperCase() + " with priority " + 
current.getPriority();
str += "]n";
current = current.getNext();
}

相关内容

  • 没有找到相关文章

最新更新