Question
File supplied.o contains code that can build, display, and destroy a linear lineked list . For this lab, you will need to write the following
File supplied.o contains code that can build, display, and destroy a linear lineked list.
For this lab, you will need to write the following two functions in list.cpp, and add function prototypes for them to list.h. The solutions need to be recursive.
- void duplicate(node *& newHead) const
recursively create a copy of the source list. newhead is the head of the destination list.
- int removeTwo()
recursively remove all the 2s from the list
//list.h #include
struct node { int data; //some questions are a char * data; node * next; };
class list { public: //These functions are already written for you list(); //supplied ~list(); //supplied void build(); //supplied void display(); //supplied /* *****************YOUR TURN! ******************************** */ //Write your function prototype here:
private: //notice there is both a head and a tail! node * head; node * tail; };
// main.cpp
#include "list.h"
int main() { list object; object.build(); //builds a LLL object.display(); //displays the LLL
//PLEASE PUT YOUR CODE HERE to call the functions
object.display(); //displays the LLL again! return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started