EBK STARTING OUT WITH C++ FROM CONTROL
EBK STARTING OUT WITH C++ FROM CONTROL
9th Edition
ISBN: 8220106714379
Author: GADDIS
Publisher: PEARSON
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
using namespace std; class SinglyLinkedListNode { // INSERT YOUR CODE HERE }; class SinglyLinkedList { public: SinglyLinkedListNode *head; SinglyLinkedListNode *tail; SinglyLinkedList() { this->head = nullptr; this->tail = nullptr; } voidinsert_node(intnode_data) { // INSERT YOUR CODE HERE } }; void free_singly_linked_list(SinglyLinkedListNode* node) { // INSERT YOUR CODE HERE } // Complete the has_cycle function below. /* * For your reference: * * SinglyLinkedListNode { * int data; * SinglyLinkedListNode* next; * }; * */ bool has_cycle(SinglyLinkedListNode* head) { SinglyLinkedListNode* temp = head; bool isCycle = false; while (temp != nullptr) { // INSERT YOUR CODE HERE } } int main() { // INSERT YOUR CODE HERE TO TEST YOUR CODE return0; }
None
in cpp please   AnyList.h #ifndef ANYLIST_H#define ANYLIST_H #include<iostream>#include <string>       //Need to include for NULL           class Node{public:   Node() : data(0), ptrToNext(nullptr) {}   Node(int theData, Node *newPtrToNext)       : data(theData), ptrToNext(newPtrToNext){}   Node* getPtrToNext() const { return ptrToNext; }   int getData( ) const { return data; }void setData(int theData) { data = theData; }   void setPtrToNext(Node *newPtrToNext)       { ptrToNext = newPtrToNext; }   ~Node(){}private:int data;      Node *ptrToNext;   //pointer that points to next node}; class AnyList{public:   AnyList();      void insertFront(int);      void print() const;    void destroyList();   ~AnyList(); private:   Node *ptrToFirst; //pointer to point to the first node in the list   int count;   //keeps track of number of nodes in the list}; #endif AnyList.cpp #include "AnyList.h" using namespace std;    //constructorAnyList::AnyList(){   ptrToFirst = nullptr;   count =…
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