please modify the following three functions from iteration torecursion.
Please supply necessary parameter(s) if needed.
display()
contains()
~LinkedList() //destructor
//Note, you can call destructor like this:this->~LinkedList(). Or you could create a recursivefunction, say, destroyAll(). In ~LinkedList(), call destroyAll().And you may want to make sure to set all member pointers toNULL.
#include <iostream>
using namespace std;
struct Node
{
int data;
Node *link;
};
class linked_list
{
private:
Node *head,*current;
public:
//constructor
linked_list()
{
head = NULL;//the headpointer
current = NULL;//acts asthe tail of the list
}
//destructor – IMPORTANT
~linked_list() {
current = head;
while( current != NULL ) {//the loop stops when both current andhead are NULL
head = head->link;
delete current;
current = head;
}
}