24 lines
625 B
Java
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;
|
|
}
|
|
}
|