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

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.

the link to the code is

https://www.chegg.com/homework-help/questions-and-answers/c-1-please-use-attached-script-reference-create-node-structure-linked-list-class-say-linke-q36479087?trackid=LNxWAReZ


Answer


#include <iostream>

using namespacestd;

struct Node

{

    int data;

    Node*link;

};

class linked_list

{

    private:

        Node*head,*current;

    public:

        //constructor

       linked_list()

        {

           head =NULL;//the head pointer

           current =NULL;//acts as the tail of thelist

        }

   

        //destructor -IMPORTANT

        ~linked_list()

        {

            this->destroyAll(this->head);

        }

       

        voiddestroyAll(Node*trav)

        {

           // if the list is empty

            if(trav != NULL)

                return;

               

           // destroy the nodes in the right sublist

            this->destroyAll(trav->link);

           

           // delete the current node

            deletetrav;

        }

   

        voidadd_node(int n)// to add a nodeat the end of

OR
OR

Leave a Comment

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