Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 3, Problem 34C
Explanation of Solution
Method clone() for CircularlyLinkedList class:
Create the method clone() to create and return the duplicate copy of receiver object for CircularlyLinkedList class.
//Define the clone() method
public CircularlyLinkedList<E> clone() throws CloneNotSupportedException
{
/*Create an object for super class of CircularlyLinkedList. */
CircularlyLinkedList<E> cObj = (CircularlyLinkedList<E>) super.clone();
/*Call the clone() method and assign that element to object of CircularlyLinkedList "cObj" element...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write the same splice method for an ArrayList with member variables called data and
size and methods grow() and rangeCheck ().
Design and implement an insertSorted() method for the MyArrayList class. The method should receive a single object and insert it in its correct position. You can assume that the calling array is already in a sorted order. The calling array is therefore updated.
Implement a recursive version of the size method for SinglyLinkedLists. (Hint: A wrapper may be useful.)
Chapter 3 Solutions
Data Structures and Algorithms in Java
Ch. 3 - Prob. 1RCh. 3 - Write a Java method that repeatedly selects and...Ch. 3 - Prob. 3RCh. 3 - The TicTacToe class of Code Fragments 3.9 and 3.10...Ch. 3 - Prob. 5RCh. 3 - Prob. 6RCh. 3 - Prob. 7RCh. 3 - Prob. 8RCh. 3 - Prob. 9RCh. 3 - Prob. 10R
Ch. 3 - Prob. 11RCh. 3 - Prob. 12RCh. 3 - Prob. 13RCh. 3 - Prob. 14RCh. 3 - Prob. 15RCh. 3 - Prob. 16RCh. 3 - Prob. 17CCh. 3 - Prob. 18CCh. 3 - Prob. 19CCh. 3 - Give examples of values for a and b in the...Ch. 3 - Suppose you are given an array, A, containing 100...Ch. 3 - Write a method, shuffle(A), that rearranges the...Ch. 3 - Suppose you are designing a multiplayer game that...Ch. 3 - Write a Java method that takes two...Ch. 3 - Prob. 25CCh. 3 - Prob. 26CCh. 3 - Prob. 27CCh. 3 - Prob. 28CCh. 3 - Prob. 29CCh. 3 - Prob. 30CCh. 3 - Prob. 31CCh. 3 - Prob. 32CCh. 3 - Prob. 33CCh. 3 - Prob. 34CCh. 3 - Prob. 35CCh. 3 - Write a Java program for a matrix class that can...Ch. 3 - Write a class that maintains the top ten scores...Ch. 3 - Prob. 38PCh. 3 - Write a program that can perform the Caesar cipher...Ch. 3 - Prob. 40PCh. 3 - Prob. 41PCh. 3 - Prob. 42PCh. 3 - Prob. 43P
Knowledge Booster
Similar questions
- Add a void instance method replaceAll(E oldE, E newE) in the MyLinkedList class to replace the occurrence of all oldE value with the specified newE value. Implement this method in O(n) time. import java.util.*; public class PExamCh24 { public static void main(String[] args) { new PExamCh24();}public PExamCh24() { // Create a list for strings MyLinkedList<String> list = new MyLinkedList<>(); // Add elements to the list list.add("America"); // Add America to the list System.out.println("(1) " + list); list.add(0, "Japan"); // Add Canada to the beginning of the list System.out.println("(2) " + list); list.add("Russia"); // Add Russia to the end of the list System.out.println("(3) " + list); list.addLast("Japan"); // Add France to the end of the list System.out.println("(4) " + list); list.add(2, "Japan"); // Add Germany to the list at index 2 System.out.println("(5) " + list); list.add(5, "Norway"); // Add Norway to the list…arrow_forwardGive an implementation of the size() method for a DoublyLinkedLIst class, assuming that we did not maintain size as an instance variablearrow_forwardWrite and test an efficient Java/Python method for reversing a doubly linked list L using only a constant amount of additional space. Hint: Add the method to DoublyLinkedList class.arrow_forward
- Write a program to test various operations of the class doublyLinkedList.arrow_forwardMake a doubly linked DoubleOrderedList class implementation. A DoubleNode class, DoubleList class, and DoubleIterator class must all be created.arrow_forwardDesign and implement a getLastHalf() method for the MyLinkedList class. The method should return the last half of the list as a new list leaving the original list intact. If the list has an uneven number of elements the extra one element must be in the list returned. Example : [1,3,5,4] return [5,4] and [1,6,9] return [6,9]. Follow the three step method for designing the method Develop the java code for the method Create a test program to test the method thoroughly using the Integer wrapper class.arrow_forward
- Design and implement a getLastHalf() method for the MyLinkedList class. The method should return the last half of the list as a new list leaving the original list intact. If the list has an uneven number of elements the extra one element must be in the list returned. Example : [1,3,5,4] return [5,4] and [1,6,9] return [6,9]. Follow the three step method for designing the method Develop the java code for the method Create a test program to test the method thoroughly using the Integer wrapper class. public class MyLinkedList<E> { private Node<E> head, tail; public MyLinkedList() { head = null; tail = null; } /** Return the head element in the list */ public E getFirst() { if (head == null) { return null; } else { return head.element; } } /** Return the last element in the list */ public E getLast() { if (head==null) { return null; } else { return tail.element; } } /** Add an element to the beginning of the list */ public void prepend(E e) { Node<E> newNode = new…arrow_forwardDesign and implement a getLastHalf() method for the MyLinkedList class. The method should return the last half of the list as a new list leaving the original list intact. If the list has an uneven number of elements the extra one element must be in the list returned. Example : [1,3,5,4] return [5,4] and [1,6,9] return [6,9]. Follow the three step method for designing the method Develop the java code for the method Create a test program to test the method thoroughly using the Integer wrapper class.arrow_forwardWrite the Java code for implementing the add method (based on index) of ArrayList class.arrow_forward
- For both ArrayList and LinkedList, which methods do not exist in the List interface? Just why do you think these methods are left out the List?arrow_forwardAdd a method findMiddle() that finds the middle node of a doubly linked list by link hopping, without relying on explicit knowledge of the size of the list. Counting nodes is not the correct way to do this. In the case of an even number of nodes, report the node slightly left of center as the middle. You can assume the list has at least one item. Your findMiddle() code will be located in DoublyLinkedList.java. If you’re using size(), you’re doing it wrong. Starter code for the findMiddle() method: // Janet McGregor 4/20/2053 public E findMiddle() { Node<E> middleNode = header.next; Node<E> currentNode = header.next; // the rest of your code goes here return middleNode.element; } You will test findMiddle() with the following three tests cases. Sample program output: Finding the middle of the list: (1, 2, 3, 4, 5, 6, 7) The middle value is: 4 Finding the middle of this list: (1, 2, 3, 4) The middle value is: 2 Finding the middle of this…arrow_forwardConsider Bag, SinglyLinkedList, and DoublyLinkedLists classes for integers. Implement and test the following methods: 1. Write a method in Bag class for integers that finds the number of odd and even numbers in the list. 5. Write a method in DoublyLinkedList class that swaps the first and last nodes in the list. 6. Write a Main class to test all these methods.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education