bartleby

Concept explainers

Question
Book Icon
Chapter 18, Problem 35RQE
Program Plan Intro

Purpose of the given code:

The given code is trying to destroy the members of a linked list by using a destructor. A destructor is called when the program ends or the destructor function calls.

Given Code:

//Definition of destructor

NumberList::~NumberList()//Line 1

{//Line 2

//Declaration of structure pointer variables

ListNode *nodePtr, *nextNode;//Line 3

//Storing "head" pointer into "nodePtr"

nodePtr = head;//Line 4

//loop

while (nodePtr != nullptr)//Line 5

{//Line 6

//Assign address of next into "nextNode"

nextNode = nodePtr->next;//Line 7

//Error

nodePtr->next=nullptr;//Line 8

//Assign nextNode into "nodePtr"

nodePtr = nextNode;//Line 9

}//Line 10

}//Line 11

Blurred answer
Students have asked these similar questions
Given the declarations struct NodeType{ int       data; NodeType* link;};NodeType* headPtr;   // External pointer to a linked listNodeType* p;Write the code that would sum all the elements in the list.
int[] findMaxMin (LinkedList liste); The method whose prototype is given above finds the maximum and minimum element in a Linked List entered as a parameter and returns the results with an array. Fill in the body of the above method accordingly. JAVA CODE   public class Node {       Node nextNode;     int data;     Node(int data){         this.data=data;         this.nextNode=null;     } }
Study the code below: public __________ ____________() {    MyLinkedList newlist = new MyLinkedList<>();     for(Node ptr=head;ptr!=null;ptr=ptr.next)    {     newlist.prepend(ptr.element);    }    return newlist;  } What is the purpose of the code

Chapter 18 Solutions

Starting Out with C++ from Control Structures to Objects Plus MyLab Programming with Pearson eText -- Access Card Package (9th Edition)

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