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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!