Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java // CustomLinkedList.java public class CustomLinkedList { public static int findMax(IntNode headObj) { int max = -1; if (headObj!=null){ max = headObj.getNodeData(); IntNode temp

In Java

image text in transcribed

// CustomLinkedList.java

public class CustomLinkedList { public static int findMax(IntNode headObj) { int max = -1; if (headObj!=null){ max = headObj.getNodeData(); IntNode temp = headObj.getNext(); while(temp !=null){ if(max

------------------------------------------------------

//IntNode.java

public class IntNode { private int dataVal; // Node data private IntNode nextNodePtr; // Reference to the next node

public IntNode() { dataVal = 0; nextNodePtr = null; }

// Constructor public IntNode(int dataInit) { this.dataVal = dataInit; this.nextNodePtr = null; }

// Constructor public IntNode(int dataInit, IntNode nextLoc) { this.dataVal = dataInit; this.nextNodePtr = nextLoc; }

/* Insert node after this node. Before: this -- next After: this -- node -- next */ public void insertAfter(IntNode nodeLoc) { IntNode tmpNext;

tmpNext = this.nextNodePtr; this.nextNodePtr = nodeLoc; nodeLoc.nextNodePtr = tmpNext; }

// Get location pointed by nextNodePtr public IntNode getNext() { return this.nextNodePtr; }

// Get node value public int getNodeData() { return this.dataVal; } // Print node value public void printNodeData() { System.out.println(this.dataVal); } }

Given the IntNode class, define the findMax() method in the CustomLinkedList class that returns the largest value in the list or returns -99 if the list is empty. Assume all values in the list are non-negative. Ex: If the list contains: head14->191186->181 findMax(headObj) returns 191 . Ex: If the list contains: head ->

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions

Question

What is meant by organisational theory ?

Answered: 1 week ago

Question

What is meant by decentralisation of authority ?

Answered: 1 week ago

Question

Briefly explain the qualities of an able supervisor

Answered: 1 week ago

Question

Define policy making?

Answered: 1 week ago

Question

Define co-ordination?

Answered: 1 week ago