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 35C
Explanation of Solution
Method clone() for DoublyLinkedList class:
Create the method clone() to create and return the duplicate copy of receiver object for DoublyLinkedList class.
//Define the clone() method
public DoublyLinkedList <E> clone() throws CloneNotSupportedException
{
/*Create an object for super class of DoublyLinkedList. */
DoublyLinkedList <E> dObj = (DoublyLinkedList <E>) super.clone();
/*Call the clone() method and assign that element to object of DoublyLinkedList "dObj" element. */
dObj...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Implement a recursive version of the size method for SinglyLinkedLists. (Hint: A wrapper may be useful.)
Write 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.
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.
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_forwardWrite a program to test various operations of the class doublyLinkedList.arrow_forwardFor the AVLTree class, create a deletion function that makes use of lazy deletion.There are a number of methods you can employ, but one that is straightforward is to merely include a Boolean field in the Node class that indicates whether or not the node is designated for elimination. Then, your other approaches must take into consideration this field.arrow_forward
- Create a class Student with the fields: name (a String) and gpa (a double). Create a linked list of Student objects, called students using the LinkedList class from java.util.Sort the linked list students “by length” of name (see Sect. 11.3 in textbook) using the sort method from class Collections.Sort the initial linked list students by gpa using the sort method from class Collections. Apply the toArray() method from class LinkedList to the initial linked list students and sort the obtained array “by length” of name using the sort method from class Arrays. After each sort, print the result.Do NOT use the sort method from the List interface (also available from a LinkedList).arrow_forwardConsider the List interface's add (i, x) and remove (i) methods. When i is big (say n-2 or n-1), which of the following is true with regards to asymptotic runtime (ignoring amortization/resize)? the ArrayDeque and (doubly) LinkedList are equal, and faster than the SkiplistList the ArrayDeque, (doubly) LinkedList, and SkiplistList are all equal the (doubly) LinkedList is faster than the ArrayDeque which is faster than the SkiplistList the ArrayDeque is faster than the (doubly) LinkedList which is faster than the SkiplistList the ArrayDeque is faster than the SkiplistList, which is faster than the (doubly) LinkedListarrow_forwardImplement the insert function in SLList class to insert an item x at a particular position in the list indexed by i. For example, let L= [1,2,3]. A call toL.insert (4,1) will make L=[1,4,2,3]. You should not change the item of existing nodes. Below is a skeleton of the Node and SLList class: template class Node public: ItemType item; Node *next; Node (ItemIype i, Node *n = nullptr) { item - i; next = n; } ; template class SLList { private: /** Pointer pointing to the sentinel node. */ Node *sentinel; /** Stores the current size of the list. */ int count; public: // Other functions omitted... void insert (const Item &x, int i) { // Copy this function in the answer and write code below this line. } };arrow_forward
- Consider 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_forwardImplement a linked list of integers as aclass LinkedList. Build the following methods:✓ print that prints the content of the linked list;✓ addFirst that adds a new node to the beginning (the head) of thelinked list;✓ addLast that adds a new node to the end (the tail) of the linked list;✓ indexOf that finds a specific node by its value, and returns node’sindex (node’s position from the left in the linked list); if the valueis not present in the linked list, it returns −1;✓ deleteFirst that deletes the first node in the linked list;✓ deleteLast that deletes the last node in the linked list.Test your class creating a list in the main and1) adding one by one nodes 2, 4, 8 to the tail;2) adding nodes -2, -8 to the head;3) adding a node 9 to the tail;4) printing the list;5) printing indexOf(4);6) printing contains(9);7) deleting one by one all the nodes in the list – either from the tail orfrom the head – and printing the result after each deletion. THEN AFTER THIS Add a new method IN THE…arrow_forwardImplement class “LinkedList” which has two private data members head: A pointer to the Node class length: length of the linked listImplement the following private method:1. Node* GetNode(int index) const;A private function which is only accessible to the class methods. . For example, index 0 corresponds to the head and index length-1 corresponds to end node of the linked list. The function returns NULL if the index is out of bound.Implement the following public methods:2. LinkedList();Constructor that sets head to NULL and length equal to zero.3. bool InsertAt(int data, int index);Insert a new node at the index. Return true if successful, otherwise,return false. The new node should be at the position “index” in the linked list after inserting it. You might have to use GetNode private function. these 3 partsarrow_forward
- Using classes , write down a program that implements creation of a head pointer of a linked list , then add first node to the list and make it pointing to null .arrow_forwardImplement a class “LinkedList” which has two private data members head: A pointer to the Node class length: length of the linked listImplement the following private method: 1. bool InsertHead(int data); // Use InsertAt FunctionInsert at the start of the linked list. Return true2. bool InsertEnd(int data); // Use InsertAt FunctionInsert at the end of the linked list. Return true3. bool RemoveAt(int index);Remove and delete the node at position “index”. Return true if successful, otherwise, false. this in c++arrow_forwardImplement a lastIndex method for the LinkedIntList class you worked on for HW4. This method takes an int argument and returns the largest index such that the int argument appears at that index in the list. If the int argument does not appear in the list, then -1 is returned. For example if the list example contained the numbers [4, -1, 2, 7, -1, 3] in that order, then example.lastIndex(-1) should return 4 and example.lastIndex(5) should return -1. In the text area below, write the definition of the lastIndex method. (In other words, write the code that should replace the //TODO comment.) Your code cannot call any methods. public class LinkedIntList { private class Node { private int item; private Node next; public Node() {} public Node(int number, Node nextNode) { item = number; next = nextNode; } } private Node first; // first node of the list public LinkedIntList() { first = null;…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