Thursday, February 9, 2023
HomeSoftware DevelopmentTips on how to create a pointer to a different pointer in...

Tips on how to create a pointer to a different pointer in a linked checklist?


  

#embody <iostream>

utilizing namespace std;

  

class Node {

  

public:

    int knowledge;

    Node* subsequent;

  

    

    Node(int knowledge)

    {

        this->knowledge = knowledge;

        this->subsequent = NULL;

    }

  

    

    ~Node()

    {

        int worth = this->knowledge;

        if (this->subsequent != NULL) {

            delete subsequent;

            this->subsequent = NULL;

        }

    }

};

  

void insertAtTail(Node*& tail, int d)

{

  

    

    Node* temp = new Node(d);

    tail->subsequent = temp;

    tail = temp;

}

  

void print(Node*& head)

{

    Node* temp = head;

  

    whereas (temp != NULL) {

        cout << temp->knowledge << " ";

        temp = temp->subsequent;

    }

    cout << endl;

}

  

Node* createPointer(Node*& head)

{

  

    Node* dummy = new Node(-1);

  

    dummy->subsequent = head;

  

    return dummy;

}

  

int predominant()

{

  

    

    

    Node* node = new Node(1);

  

    

    Node* head = node;

    Node* tail = node;

  

    insertAtTail(tail, 2);

    insertAtTail(tail, 3);

    insertAtTail(tail, 4);

    insertAtTail(tail, 5);

  

    cout << "Linked Listing: " << endl;

  

    print(head);

  

    Node* pt = createPointer(head);

  

    cout

        << "Dummy pointer pointing to move of Linked Listing: "

        << endl;

  

    print(pt);

  

    return 0;

}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments