Given this definition of a generic Linked List node:
public class LLNode { private T data; private LLNode next; public LLNode(T data, LLNode next) { this.data = data; this.next = next; } public void setNext(LLNode newNext){ next = newNext; } public LLNode getNext(){ return next; } public T getData() {return data;} }
Write the findMinimumNode method body. This method returns the linked list node that contains the minimum value in the linked list given by the parameter head. Your implementation should be O(n) where n is the number of elements in the linked list. Assume T is a Comparable object.
public LLNode findMinimumNode(LLNode head) { //your code. }
in Java
public class LLNode {
private T data;
private LLNode next;
public LLNode(T data, LLNode next) {
this.data = data;
this.next = next;
}
public void setNext(LLNode newNext){
next = newNext;
}
public LLNode getNext(){
n next;
}
public T getData() {ndata;
}
}
public LLNode findMinimumNode(LLNode head) {
int min = Integer.MAX_VALUE;
while (head != null) {
if (min > head.data)
min = head.data;
head = head.next;
}
return min;
}
Get Answers For Free
Most questions answered within 1 hours.