내 코드를 실행할 때마다 프로그램이 영원히 계속 될 때마다 연결된 목록의 모든 항목이 완벽하게 작동합니다. 삭제를 포함하여링크 된 목록에서 가장 작은 값을 찾는다.
public Node smallestValue() {
Node current = firstL;
int min = current.data;
if (!isEmpty()) {
while (current != null) {
if (min < current.data) {
min = current.data;
current = current.next;
}
}
} else {
System.out.println("empty list");
}
System.out.println();
System.out.println(min);
return current;
}
'current = current.next'를'if' 문 밖으로 옮깁니다. – Oswald
그리고 조건이 잘못되었습니다. 'if (min> current.data)'이어야합니다. – 0x499602D2