Please Modify Following Three Functions Iteration Recursion Please Supply Necessary Parame Q37205670

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;
}

    }

   

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.