Question

Given this definition of a generic Linked List node: public class LLNode {     private T...

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

Homework Answers

Answer #1

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;  

}  

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
(Please use Java Eclipse) QUESTION 1: For the question below, assume the following implementation of LinkedQueue:...
(Please use Java Eclipse) QUESTION 1: For the question below, assume the following implementation of LinkedQueue: public static final class LinkedQueue<T> implements QueueInterface<T> {     private Node<T> firstNode;     private Node<T> lastNode;     public LinkedQueue() {         firstNode = null;         lastNode = null;     }     @Override     public T getFront() {         if (isEmpty()) {             return null;         }         return firstNode.getData();     }     @Override     public boolean isEmpty() {         return firstNode == null;    ...
Question: I get a Segmentation fault error sometimes when I addElementBack or print. Am I using...
Question: I get a Segmentation fault error sometimes when I addElementBack or print. Am I using pointers correctly and deleting memory properly? #ifndef DYNAMICARRAY_H #define DYNAMICARRAY_H #include <cstdlib> #include <iostream> using namespace std; // Node class class Node { int data; Node* next; Node* prev; public: Node(); Node(int); void SetData(int newData) { data = newData; }; void SetNext(Node* newNext) { next = newNext; }; void SetPrev(Node* newPrev) { prev = newPrev; }; int getData() { return data; }; Node* getNext()...
The class CourseList implements a simple database of students registered in a course. Complete the method...
The class CourseList implements a simple database of students registered in a course. Complete the method countAttendees in the code below such that it returns the number of students in the instance of CourseList who have not attended any classes. Your response may be written in Java or pseudocode. Your code cannot modify the linked list. The class Node is similar to the linked list node object discussed in lecture. You can use helper methods, but this is not necessary....
In this code, I build a single-linked list using a node class that has been created....
In this code, I build a single-linked list using a node class that has been created. How could I change this code to take data of type T, rather than int. (PS: ignore the fact that IOHelper.getInt won't work for the type T... ie second half of main). Here's my code right now: public class SLList { public SLNode head = null; public SLNode tail = null; public void add(int a) {// add() method present for testing purposes SLNode newNode...
Complete the redblacktree in Java. Add a public boolean isBlack field to the Node inner class....
Complete the redblacktree in Java. Add a public boolean isBlack field to the Node inner class. Make every Node object have a false isBlack field, all new node is red by default. In the end of the insert method, set the root node of your red black tree to be black. Implement the rotate() and recolor() functions, and create tests for them in a separate class. import java.util.LinkedList; public class BinarySearchTree<T extends Comparable<T>> { protected static class Node<T> { public...
c++ data structures linked list delete node bool deleteNode(int); pass this method an id to delete....
c++ data structures linked list delete node bool deleteNode(int); pass this method an id to delete. Return true or false to indicate success or failure. Delete the memory the node was using The algorithm for deleting a Node to a Linked List (general case): ● Begin at the head. ● Compare the id to the current node. ● If search id > current id, stop. ● Detach the current Node ○ current->previous->next = current->next ○ current->next->previous = current->previous ● Deallocate...
Consider a linked implementation of a Stack. Implement the pop() method below. Assume a typical singly...
Consider a linked implementation of a Stack. Implement the pop() method below. Assume a typical singly linked node, with an instance variables data and next. public class LinkedStack<T> implements Stack<T> { private Node<T> head;    public LinkedStack() { head = new Node<T>(); } // pops the top item off the stack // returning the popped value // throw an EmptyStackException if there are no // items in the stack public T pop() { // write your implementation below } }
could you implement this function please, im having issues with it. void makeList (const ListNode::value_type [],const...
could you implement this function please, im having issues with it. void makeList (const ListNode::value_type [],const size_t& count) class ListNode { public: typedef int value_type; ListNode (value_type d = value_type(), ListNode* n = NULL) { datum = d; next = n; }    //Assessor value_type getDatum () const { return datum; } ListNode const* getNext () const { return next; }    //Mutator void setDatum (const value_type& d) {datum = d; } ListNode* getNext () { return next; } void...
Finish the code wherever it says TODO /**    * Node type for this list. Each...
Finish the code wherever it says TODO /**    * Node type for this list. Each node holds a maximum of nodeSize elements in an    * array. Empty slots are null.    */    private class Node {        /**        * Array of actual data elements.        */        // Unchecked warning unavoidable.        public E[] data = (E[]) new Comparable[nodeSize];        /**        * Link to next node.       ...
The following program creates a linked list which contains 5 links. Add a method called doubleValue()...
The following program creates a linked list which contains 5 links. Add a method called doubleValue() to the LinkedList class. The doubleValue() method must double the value of the number data field in each link. Add the required code to the main() method to call the doubleValue() method and display the revised list. public class Link { private int number; private Link next;      public Link(int x) { number = x; }    public void displayLink() { System.out.println("The number is:...