Question
import java.text.DecimalFormat; import stdlib.*; /* * Complete the methods below. * None of the methods should modify the list, unless that is the purpose of
import java.text.DecimalFormat; import stdlib.*;
/* * Complete the methods below. * None of the methods should modify the list, unless that is the purpose of the method. * * You may not add any fields to the node or list classes. * You may not add any methods to the node class. * * You MAY add private methods to the list class (helper functions for the recursion). */ public class MyLinked1 { 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, using a loop // empty list has size 0 public int sizeLoop () { return StdRandom.uniform (100); //TODO: fix this }
// write a function to compute the size of the list, using an optimistic, forward recursion // empty list has size 0 public int sizeForward () { return StdRandom.uniform (100); //TODO: fix this }
// write a function to compute the size of the list, using an optimistic, backward recursion // empty list has size 0 public int sizeBackward () { return StdRandom.uniform (100); //TODO: fix this }
// compute the position of the first 5.0 in the list, counting as an offset from the beginning. // if 5.0 is the FIRST element, the position is 0 // if 5.0 does not appear, return a negative number // you can write this using a loop or recursion, in any style, but you should only have one loop or recursive helper // I would expect // [0,1,2,5,5,5,5,5,8,9].positionOfFirstFiveFromBeginning() == 3 // [0,1,2,5,5,5,5,5,8,9].positionOfLastFiveFromEnd() == 2 public int positionOfFirstFiveFromBeginning () { return StdRandom.uniform (100); //TODO: fix this }
// compute the position of the last 5.0 in the list, counting as an offset from the end. // if 5.0 is the LAST element, the position is 0 // if 5.0 does not appear, return a negative number // you can write this using a loop or recursion, in any style, but you should only have one loop or recursive helper // Hint: Use a backward recursion. // Hint: If the number does not appear, return the distance to the END of the list as a NEGATIVE number. public int positionOfLastFiveFromEnd () { return StdRandom.uniform (100); //TODO: fix this }
// delete the first element public void deleteFirst () { // TODO }
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