Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
3rd Edition
ISBN: 9780134038179
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 20.3, Problem 20.4CP
Explanation of Solution
Code for add an element “e” to the end of the list:
The code for add an element “e” to the end of the doubly linked list is given below:
//Create a new node with an element "e"
Node new_node = new Node(e);
//Set next of new node pointing to "null"
new_node.next = null;
//Store the address of new node into next of last node
last.next = new_node;
//Store the address of last node into previous of new node
new_node...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Add a new public member function to the LinkedList class named reverse() which reverses the items in the list. You must take advantage of the doubly-linked list structure to do this efficiently as discussed in the videos/pdfs, i.e. swap each node’s prev/next pointers, and finally swap headPtr/tailPtr. Demonstrate your function works by creating a sample list of a few entries in main(), printing out the contents of the list, reversing the list, and then printing out the contents of the list again to show that the list has been reversed.
Note: your function must actually reverse the items in the doubly-linked list, not just print them out in reverse order!
Note: we won't use the copy constructor in this assignment, and as such you aren't required to update the copy constructor to work with a doubly-linked list.
This is what I have so far but its not working!
template<class ItemType>void LinkedList<ItemType>::reverse(){ Node<ItemType>*curPtr,*prev,*next;…
Implements clone which duplicates a list. Pay attention, because if there are sublists, they must be duplicated as well. Understand the implementation of the following function, which recursively displays the ids of each node in a list
Develop your solution as follows:
First copy the nodes of the current list (self)
Create a new list with the copied nodes
Loop through the nodes of the new list checking the value field
If this field is also a list (use isinstance as in the show_ids function) then it calls clone on that list and substitutes the value.
Complete the code:
def L4(*args,**kwargs): class L4_class(L):
def clone(self):
def clone_node(node): return <... YOUR CODE HERE ...>
r = <... YOUR CODE HERE...> return r return L4_class(*args,**kwargs)
Write a program which should implement a linear linked list. Elements of this linked list
should be of integer type, user will provide values as input for elements of this linked list.
Your program should allow searching of a value specified by user in linked list and
display also it index.
Chapter 20 Solutions
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Ch. 20.1 - Prob. 20.1CPCh. 20.1 - Prob. 20.2CPCh. 20.3 - Prob. 20.4CPCh. 20 - A list is a collection that _____. a. associates...Ch. 20 - Prob. 2MCCh. 20 - Prob. 3MCCh. 20 - Prob. 4MCCh. 20 - Prob. 5MCCh. 20 - Prob. 6MCCh. 20 - Prob. 7MC
Ch. 20 - Prob. 11TFCh. 20 - Prob. 12TFCh. 20 - Prob. 13TFCh. 20 - Prob. 14TFCh. 20 - Prob. 15TFCh. 20 - Prob. 16TFCh. 20 - Prob. 17TFCh. 20 - Prob. 18TFCh. 20 - Prob. 29TFCh. 20 - Prob. 20TFCh. 20 - Prob. 1FTECh. 20 - Prob. 2FTECh. 20 - Prob. 3FTECh. 20 - Prob. 4FTECh. 20 - Prob. 5FTECh. 20 - Prob. 1AWCh. 20 - Prob. 2AWCh. 20 - Prob. 3AWCh. 20 - Prob. 4AWCh. 20 - Prob. 3SACh. 20 - Prob. 4SACh. 20 - Prob. 5SACh. 20 - Consult the online Java documentation and...Ch. 20 - Prob. 1PCCh. 20 - Prob. 2PC
Knowledge Booster
Similar questions
- Given a singly linked list, print reverse of it using a recursive function printLinkedList( node *first ) where first is the pointer pointing to the first data node. For example, if the given linked list is 1->2->3->4, then output should be: 4 3 2 1 (note the whitespace in between each data value)arrow_forward} (1 of 3 parts) Consider the function below that is given the head and tail pointers to a double linked list. bool patronum (Node ✶h, Node * t) { bool c = true; if (t nullptr) return true; Node* p = t; while (p != h) { Node* j = p; Node* r = p->prev; EXAM for (Node* r = p->prev; r != nullptr; r = r->prev) { if (j->value > r->value) { c = false; j = r; } swap(p->value, j->value); p = p->prev; return c;arrow_forwardWrite a program which should implement a linear linked list. Elements of this linked list should be of integer type, user will provide values as input for elements of this linked list. Your program should allow searching of a value specified by user in linked list and it will also allow deletion of a value specified by user.arrow_forward
- You may do this assignment using either Java or C++. Do *not use the JDK LinkedList class or any linked list library! A linked list consists of zero or more nodes, which each contain one item of data and a link (Java reference, C++ pointer or reference) to the next node, if there is one. Linked List code is usually generic, so that you can use it to create a list of Strings, Students, Doubles, etc. For this assignment, you will write a simplified version of linked list that only can be used to create and use a list of ints and that has only a few of the functions typical of linked lists. The data element can be just an int, and the data type of the link to the next node can be just Node. You will need a reference (Java) or either a reference or a pointer (C++) to the first node, as well as one to the last node. Write a method/function that takes an in, creates a node with that int as its data value, and adds the node to the end of the list. This function will need to update the…arrow_forwardefficiency ! Write a function to be included in an unsorted doubly linked list class, called deleteLast, that will delete the last node in the list. Assume that there is only pointer first (no last pointer).arrow_forwardtry to ans in ten minarrow_forward
- For a singly linked list pointed at by pointer Ptr, write the implementation of a function named CountPositive that counts and prints the nodes with positive value in the list. Take in consideration all special cases. (** The declaration of the Node is: typedef struct Node { int data; Node*next; }Node;arrow_forwardIn c++ pleasearrow_forwardThink about the following example: A computer program builds and modifies a linked list like follows:Normally, the program would keep tabs on two unique nodes, which are as follows: An explanation of how to use the null reference in the linked list's node in two common circumstancesarrow_forward
- Think about the following example: A computer program builds and modifies a linked list like follows: Normally, the program would keep tabs on two unique nodes, which are as follows: An explanation of how to use the null reference in the linked list's node in two common circumstancesarrow_forwardImplement a function to insert a node at the end of a doubly linked list. Explain the steps involved and analyze the time complexity of your implementation.arrow_forwardWrite a void function that takes a linked list of integers and removes all the duplicate elements from the list. The function will have one call-by-reference parameter that is a pointer to the head of the list. After the function is called, this pointer will point to the head of a linked list that has the nodes that have all the distinct integers. Place your function in a suitable test program.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