Question
// Exercise 1: Manipulating linked lists in C++ #include // Link is a data type for a linked list of integers class Link { public:
// Exercise 1: Manipulating linked lists in C++
#include
// Link is a data type for a linked list of integers
class Link
{
public:
int value;
Link* tail;
Link(int v, Link* t) : value(v), tail(t) {}
~Link()
{
if (tail) delete tail;
}
void print_list()
{
std::cout << value;
if (tail)
{
std::cout << ", ";
tail->print_list();
}
else
std::cout << std::endl;
}
};
// Return the reverse of the input list, as a new list.
// Do not modify the input list, but build a fresh list for its reverse.
Link* reverse_list(Link* lst)
{
// TODO
return 0;
}
// Return the index of an element in the provided list, or -1 if it does not exist.
int find_in_list(Link* lst, int element)
{
// TODO
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