EBK STARTING OUT W/JAVA:...DATA...
EBK STARTING OUT W/JAVA:...DATA...
4th Edition
ISBN: 9780134757179
Author: GADDIS
Publisher: PEARSON CO
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 19, Problem 5FTE

Explanation of Solution

Purpose of the given code:

The given code is used to remove the last node from a nonempty doubly linked list “myList”.

Given code:

/* The reference last points to the last node in a nonempty doubly linked list. Remove the last node from the list */

last = last.prev;

Error in the given code:

First, user needs to check if the list is nonempty, and also have to undo the removed node, and then set the next reference of the new last node to null.

/* If the last node is equal to "null", then */

if (last == null)

  /* Set "first" to "null" */

  first = null;

//Otherwise

else

{

  /* Set the reference "prev" of last node to "null" */

  last.next.prev = null;

  /* Set next node of last to "null" */

  last.next = null;

}

Corrected code:

/* The reference last points to the last node in a nonempty doubly linked list...

Blurred answer
Students have asked these similar questions
Multiple choice in data structures void doo(node<int>*root){ if(root !=0) { node<int>*p=root; while(root->next!=0) root=root->next; p->data=root->data; } What is this code do? a. swap the first item with the last item in the linked list b. set the first item in the linked list as the last item c. doesn't do anything because the root parameter is passed by value d. change the root item in the binary tree with the farthest leaf item
It is a to the next node in the linked list, which is the property after it in the Node class.
With Head node or not? statement is: if(p->rlink != first) p = p->rlink; O a. It is a Doubly linked list without Head node. O b. It is a Doubly linked list with Head node.
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education