Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the definitions of the classes Node and List below, define the member function insert_after and the destructor. The member function insert_after passes in the

Given the definitions of the classes Node and List below, define the member function insert_after and the destructor.

The member function insert_after passes in the address to a Node (Node pointer) currently in the list and an integer value to be inserted into the list. This function should then create a new Node containing this integer value passed in and insert it into the list after the Node whose address is passed in. If the address passed in is 0, then insert the new Node at the front of the List.

The insert_after function is a private helper function that will be used within the insert_sorted public member function. You DO NOT need to define the insert_sorted function.

The destructor should ensure there are no memory leaks.

Notice there are no push_front, push_back or pop_front functions declared or defined for this List class. You may NOT define these or any other member functions, even as private helper functions.

struct Node {

 public: Node *next; int data; Node(int val) 
 : next(0), data(val) {} 

};

class List {

 private: Node *head; Node *tail; 

public: List() : head(0), tail(0) {} ~List(); //IMPLEMENT void insert_sorted(int); //DON'T IMPLEMENT

private:

void insert_after(Node *, int); //IMPLEMENT

};

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

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions

Question

=+With whom does the firm have to negotiate?

Answered: 1 week ago

Question

=+Are there shop stewards?

Answered: 1 week ago