Question: c++ language list.h #include #include #include #include //The data structure is a linear linked list of integers //with a head AND tail pointer! struct node
c++ language
list.h
#include
#include
#include
#include
//The data structure is a linear linked list of integers
//with a head AND tail pointer!
struct node
{
int data;
node * next;
};
class list
{
public:
//These functions are supplied for you
list();
~list();
void build();
void display_all();
//****************************************************
//Write each of these functions Iteratively and Recursively
int sum_total(); //Iterative
int sum_total(node * head); // Recursive
bool remove_last(); //Iterative
bool remove_last(node * & head, node * & tail); //Recursive
bool remove_all(); //Iterative
bool remove_all(node * & head); //Recursive
bool find_item(int item_to_find); //Iterative
bool find_item(node * head, int item_to_find); //Recursive
bool copy(list & from); //Iterative
bool copy(node * & dest_head, node * & dest_tail, node * source ); //Recursive
private:
//Notice there is BOTH a head and tail pointer
//Make sure to keep both properly maintained
node * head;
node * tail;
};
list.cpp
#include "list.h"
using namespace std;
//Sum all of the data together in a LLL
int list::sum_total()
{
//FIRST do this iteratively here. Then recursively
//COMMENT out the iterative version when rewriting
//the solution recursively
//To solve this recursively write another
//function: int sum_total(node * head);
//and call it from this function
}
//Now implement the function recursively!
int list::sum_total(node * head)
{
}
// *************************************************
//Remove the last node in a LLL. Return false if the
//list is empty and nothing is removed
bool list::remove_last()
{
//Write your code here
//FIRST do this iteratively here. Then recursively
//COMMENT out the iterative version when rewriting
}
//Now implement the function recursively!
bool list::remove_last(node * & head, node * & tail)
{
}
// ************************************************
//Remove all nodes in a LLL. Remove false if there is
//nothing to remove
bool list::remove_all()
{
//Remove all nodes in a LLL
//FIRST do this iteratively here. Then recursively
//COMMENT out the iterative version when rewriting
}
//Now implement the function recursively!
bool list::remove_all(node * & head)
{
}
// ************************************************
//Return true if the requested item (sent in as an argument)
//is in the list, otherwise return false
bool list::find_item(int item_to_find)
{
//Write your code here
}
//Now implement the function recursively!
bool list::find_item(node * head, int item_to_find)
{
}
// ************************************************
//Make a complete copy of a LLL
bool list::copy(list & from)
{
//Write your code here
}
//Now implement the function recursively
bool list::copy(node * & dest_head, node * & dest_tail, node * source)
{
}
main.cpp
#include "list.h"
using namespace std;
int main()
{
//First try this out as is. Then start adding in your function calls!
list my_list;
my_list.build();
my_list.display_all();
//PLACE YOUR FUNCTION CALL HERE!
my_list.display_all();
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
