Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

DRAW the following linked list as it would look when calling the draw function. Each node should be represented by a rectangle containing the assigned

DRAW the following linked list as it would look when calling the draw function. Each node should be represented by a rectangle containing the assigned integer and showing where all pointers point by using directed arrows.

Explain any memory leaks that exist in the code (if any). Clearly identify any nodes that are unreachable (if any).

ATTACH a picture of your labled linked list.

supporting code for reference:

namespace DSLLI { class node { public: typedef int value_type; //Constructor node(value_type d = value_type(), node * n = nullptr) : data_field(d), next_ptr(n) {} //Assessor/Getters const value_type& getData() const { return data_field; } node const * getNext() const { return next_ptr; } //Mutators/Setters void setData(const value_type& new_data) { data_field = new_data; } void setNext(node * new_link) { next_ptr = new_link; } //Other value_type& data() { return data_field; } node*& next() { return next_ptr; } private: value_type data_field; node* next_ptr; }; } /* namespace DSLLI */ //Precondition: head points to a linked list, when the list is empty, head will point to nullptr //Postcondition: A graphical (not-ASCII) representation of the linked list is displayed. // Each node is represented as a clear rectange containing integer data and a pointer to the next node. // All pointers pointing to the linked list are displayed as named directed arrows, even pointers that are not in scope (amazing) will be displayed. // Null is represented as a line that ends in an X, the word null, or three perpindicular lines (ground, see https://www.allaboutcircuits.com/uploads/articles/Davis_ground_1.jpg). // THIS IS NOT MEANT TO BE CODED BY YOU, you are to DRAW the linked list freehand as if this function worked void draw(node * head); //Precondition: head points to a linked list, when the list is empty, head will point to nullptr void clear(node * head) { while ( head != nullptr ) { node * temp = head; head = head->next(); delete temp; } }

code to draw:

node * h = nullptr; node * c = new node(25, new node(44)); h = new node(33, c); h->next()->data() = h->data() * 2; h->next()->next() = new node(77); draw(h); clear(h);

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

Students also viewed these Programming questions