Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a java function that returns the maximum value in a circular doubly linked

ID: 3566620 • Letter: W

Question

Write a java function that returns the maximum value in a circular doubly linked list of integers, given the cursor c that points to a node in the list.Write a java function that returns the maximum value in a circular doubly linked list of integers, given the cursor c that points to a node in the list.

Explanation / Answer

class ListNode{ int item; ListNode next; } class RecursiveMax{ public static int max(ListNode node,int maxValue){ //is this the base case ? //if last node reached return the current maxValue if(node==null){ return maxValue; }else{ int v = node.item; if(v > maxValue){ return max(node.next,v); }else{ return max(node.next,maxValue); } } } public static void main(String[] args) { ListNode a = new ListNode(); a.item = 11; ListNode b = new ListNode(); b.item = 9; ListNode c = new ListNode(); c.item = 21; ListNode d = new ListNode(); d.item = 17; a.next = b; b.next = c; c.next = d; System.out.println("max value in linkedlist="+max(a,0)); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote