CS1083/Submissions/Final/Q4.java
2022-10-07 00:44:12 -03:00

24 lines
625 B
Java

import java.util.NoSuchElementException;
public class Q4 {
public void removeLowestGrade () {
if (head == null) {
throw new NoSuchElementException("List was empty");
}
if (head.next == null) {
//if only one element
head = null;
}
GradeNode smallest = head;
GradeNode index = head;
while(index.next != null) {
if (index.next.grade < smallest.grade) {
smallest = index;
}
index = index.next;
}
smallest.next = smallest.next.next;
}
}