Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.text.DecimalFormat; import stdlib.*; /* * Complete the methods below. * See the tests in main for examples of what each function should do. *

image text in transcribed

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"); }

Inport fava, text, Dectnalfornaty inpert swimtion - Complete the nethods belon. - See the tests in motn for exaptes of whot eadt function should do. - deleterirst should nedify the list. None of the other methods should madtfy the List. - Vou noy not edd any ftelds to the node or list classes. - Vou nay not add any methods to the node class. - Vou may not create any nen node objects or other obiects. - For exalple, you cannot create a nen Stadh or Arroylist. Each function nust be thdependent yau eanhot call one solution funct ton frow the other: vou MIY ode privote methods to the list class (helper functions for recurstong tf you ehose to use th). i. pubtie class Wyitnkedo Btrite crass note pubte doubte then public Node nexty Nithe Prest A) urite a function to coupute the stze of the list puible int stfe () in II Irite e function to coupute the suin of the positive etenents of the Itist Public domble sumpostrivezlenents () return sk 2 Af delete the first elenent froin this list, if th extsts Af cle nothing if the list is enipty . Il return the tength of the comion prefix for this and that a II return true If the even indexed eterents oce strietty thereasing i) Himinpebug ( ) Prtvate statte vold eatnochue () A. Uie this for dobyeghat Ifacendrassespof of hether functions If you wse then tostshe (c, she test here you mont to deoug

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

More Books

Students also viewed these Databases questions

Question

8. In what situations is aggression most likely to occur?

Answered: 1 week ago

Question

assess the infl uence of national culture on the workplace

Answered: 1 week ago