Question: /* * CSCHomework6 version 1.0 * * this class maintains a linked structure via the instance variable first * As an abstract data type, you

/* * CSCHomework6 version 1.0 * * this class maintains a linked structure via the instance variable first * As an abstract data type, you should think of this class as a linked list * * Complete the method below marked ToDo * None of the methods should modify the list, unless that is the express purpose of the method. * * You may not add any instance variables to the node or list classes. * You may not add any methods to the node class. * * You may not use the toString method to solve any of the toDos * You may use the toString method for debugging - e.g. to print the list contents * * You may add private methods to the CSCHomework6 class (helper functions for the recursion). * * You may NOT use arrays or other Java classes without permission. */

static class Node { public Node (char item, Node next) { this.item = item; this.next = next; } public char item; public Node next; }

Node first; // this is the only instance variable, // the access point to the list //This is the problem to complete. Solve lastMletters iteratively or recursively using a linked list. /* * lastMletters * * return a string consisting of the last m letters in the list, where m is a * parameter * Precondition: the list has at least m nodes * * Examples: * ["ababcdefb"].lastMletters(2) == "fb" * ["ababcdefb"].lastMletters(4) == "defb" * * You can write this iteratively or recursively, but for full credit you should only * have one loop or recursive helper * * You may not use any methods from the String class except length * Suggestion: * start with an empty string and concatenate chars to it * Concatenation example: * String x = "Jim"; * x = x + 'q'; // adds 'q' on to the right end of "Jim" */ public String lastMletters (int m) { return "TODO";} //TODO 1: fix this

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!