Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public LinkedList findMaximumSubList(LinkedList nums) This method should return a new LinkedList that represents the maximum sublist of the given LinkedList, nums. For example, the maximum

public LinkedList findMaximumSubList(LinkedList nums) This method should return a new LinkedList that represents the maximum sublist of the given LinkedList, nums. For example, the maximum sublist of 13->-3->-25->-20->-3->-16->-23->18->20->-7->12->-5->-22->15->-4->7 is 18->20->-7->12

public int[] findMaximumSubArray(int[] nums) This method should return a new int[] that represents the maximum subarray of the given int[], nums. For example, the maximum subarray of [13,-3,-25,-20,-3,-16,-23,18,20,-7,12,-5,-22,15,-4,7] is [18,20,-7,12]

FindMaxSub.java

package subarray;

import subarray.LinkedList.Node;

public class FindMaxSub { public static LinkedList findMaximumSubList(LinkedList nums) { return new LinkedList(); } public static int[] findMaximumSubArray(int[] nums){ return new int[0]; }

}

LinkedList.java (Do not change anything in this file)

package subarray;

public class LinkedList { //inner class that creates Nodes for the LinkedList static class Node { int data; Node next; Node(int data) { this.data = data; next = null; } Node(int data, Node next) { this.data = data; this.next = next; } } //Node that starts the LinkedList Node head; //Constructor that converts an int array to a LinkedList LinkedList(int[] nums) { for(int i: nums) { insert(i); } } //No argument constructor LinkedList() { head = null; } /* * Creates a sublist from the LinkedList from the start node * to the end node * Running sublist on 1->2->3->4->5 with start = 2 and end =4 * returns the new LinkedList:2->3->4 */ LinkedList subList(Node start,Node end) { LinkedList sub = new LinkedList(); Node current = head; while(current!=start) { current = current.next; } sub.insert(current.data); if(start==end) return sub; current = current.next; while(current!=end) { sub.insert(current.data); current = current.next; } sub.insert(current.data); return sub; } /* * insert a new node at the end of the LinkedList * with data equal to i */ void insert(int i) { if(head==null) { head = new Node(i); } else { Node current = head; while(current.next != null) { current = current.next; } current.next = new Node(i); } } boolean isEmpty() { return head==null; } //string representation of the linked list //useful for debugging public String toString() { String s = ""; if(isEmpty()) return s; Node current = head; while(current!=null) { s = s+current.data + "->"; current = current.next; } return s.substring(0,s.length()-2); }

}

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

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions

Question

600 lb 20 0.5 ft 30 30 5 ft

Answered: 1 week ago

Question

Develop skills for building positive relationships.

Answered: 1 week ago

Question

Describe techniques for resolving conflicts.

Answered: 1 week ago

Question

Give feedback effectively and receive it appropriately.

Answered: 1 week ago