Question
import java.text.DecimalFormat; import stdlib.*; /* * Complete the methods below. * See the tests in main for examples of what each function should do. *
import java.text.DecimalFormat; import stdlib.*;
/* * Complete the methods below. * See the tests in main for examples of what each function should do. * * deleteFirst should modify the list. * None of the other methods should modify the list. * * You may not add any fields to the node or list classes. * You may not add any methods to the node class. * You may not create any new node objects or other objects. * For example, you cannot create a new Stack or ArrayList. * * Each function must be independent: you cannot call one solution function from the other. * You MAY add private methods to the list class * (helper functions for recursion, if you chose to use it). */ public class MyLinked0 { static class Node { public Node (double item, Node next) { this.item = item; this.next = next; } public double item; public Node next; } Node first;
// write a function to compute the size of the list public int size () { return StdRandom.uniform (100); //TODO }
// write a function to compute the sum of the positive elements of the list public double sumPositiveElements () { return StdRandom.random (); //TODO }
// delete the first element from this list, if it exists // do nothing if the list is empty public void deleteFirst () { // TODO }
// return the length of the common prefix for this and that public int lengthOfCommonPrefix (MyLinked0 that) { return StdRandom.uniform (100); //TODO }
// return true if the even indexed elements are strictly increasing public boolean evenIndicesIncreasing () { return StdRandom.bernoulli(); //TODO }
public static void main (String args[]) { //mainDebug (); mainRunTests (); } private static void mainDebug () { // Use this for debugging! // Uncomment the call in main to use this. // Add the names of helper functions if you use them. Trace.drawStepsOfMethod ("size"); Trace.drawStepsOfMethod ("sumPositiveElements"); Trace.drawStepsOfMethod ("deleteFirst"); Trace.drawStepsOfMethod ("evenIndicesIncreasing"); Trace.drawStepsOfMethod ("lengthOfCommonPrefix"); Trace.run (); // TODO: Put the test here you want to debug: testSize (4, "11 -21.2 31 41"); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started