so im writing a function that will find the second largest key in an un-ordered symbol table using a linked list implementation, the code I have so far isnt working right and was wondering if someone had any tips thanks!
public Key secondLargestKey () {
if(first == null) return null;
if(size()<=1) return null;
Node secondMax=null;
Node Max=first;
for (Node pointer=first.next;pointer.next!=null;pointer=pointer.next) {
if(Max.key.compareTo(pointer.key)<=0) {
secondMax=Max;
Max=pointer.next;
}
else {
secondMax=Max.next;
Max=pointer;
}
}
return Max.key;
}`
Output:
secondLargestKeyTest: Correct String Answer: null
secondLargestKeyTest: Correct String A Answer: null
secondLargestKeyTest: *Error* String AB Expected A Actual: B
secondLargestKeyTest: Correct String ABC Actual: B
secondLargestKeyTest: Correct String ABABABC Actual: B
secondLargestKeyTest: *Error* String ZAYBXC Expected Y Actual: Z