Implement a recursive function void deleteMax() on the IntList class (provided). The function will delete from the IntList the IntNode containing the largest value. If there are multiple nodes containing this largest value, only delete the 1st one. Be careful not to cause any memory leaks or dangling pointers. You may NOT use any kind of loop (must use recursion). You may NOT use global or static variables. You may NOT use any s

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Implement a recursive function void deleteMax() on the IntList class (provided). The function will delete from the IntList the IntNode containing the largest value. If there are multiple nodes containing this largest value, only delete the 1st one.

Be careful not to cause any memory leaks or dangling pointers.

You may NOT use any kind of loop (must use recursion).

You may NOT use global or static variables.

You may NOT use any standard library functions.

 

Ex:

list: 5->7->1->16->4->16->3

list.deleteMax();

list: 5->7->1->4->16->3

 

IntList.h

#ifndef __INTLIST_H__
#define __INTLIST_H__

#include <ostream>

using namespace std;

struct IntNode {
int value;
IntNode *next;
IntNode(int value) : value(value), next(nullptr) {}
};


class IntList {

private:
IntNode *head;

public:

/* Initializes an empty list.
*/
IntList() : head(nullptr) {}

/* Inserts a data value to the front of the list.
*/
void push_front(int val) {
if (!head) {
head = new IntNode(val);
} else {
IntNode *temp = new IntNode(val);
temp->next = head;
head = temp;
}
}

/* Outputs to a single line all of the int values stored in the list, each separated by a space.
This function does NOT output a newline or space at the end.
*/
friend ostream & operator<<(ostream &out, const IntList &rhs) {
if (rhs.head) {
IntNode *curr = rhs.head;
out << curr->value;
for (curr = curr->next ; curr ; curr = curr->next) {
out << ' ' << curr->value;
}
}
return out;
}


/* Deletes the 1st instance of the largest value from the list,
keeping all other values in the same relative order.
*/
void deleteMax();

private:


/* Recursive helper function that passes in a node (actually the address of a node)
and the largest value that exists from the head to curr (inclusive).
This function should delete the node after curr if that node contains the first instance
of the largest value within the entire list.
This function returns the largest integer that exists (or existed if deleted) after the curr node.
*/
int deleteMax(IntNode *curr, int leftMaxVal);
};

 

#endif

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 4 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY