Linked List adding nodes..

Ok so I am having difficulty adding nodes to my linked list....

Can someone give me an example of how to add a third node while keeping track of the address...Thats where I get lost..I don't know how to keep track of the addresses of the next node...Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>

using namespace std;

typedef struct Node{
    int data;
    Node* link;
}Node;

int main()
{
    Node *newNode, *head, *tail;
    
    newNode = new Node;
    newNode->data = 5;
    newNode->link = NULL;
    
    head = newNode;
    head->link = newNode;
    
    tail = newNode;
    tail->link = newNode;
    
    cout << "Head Address" << endl;
    cout << newNode << endl;
    cout << head->link << endl;
    
    newNode = new Node;
    newNode->data = 10;
    newNode->link = NULL;
    
    tail = newNode;
    tail->link = newNode;

    cout << endl;
    cout << "Tail Address" << endl;
    cout << newNode << endl;
    cout << tail << endl;
    
    
    
    return 0;
}

can someone please help me out.
Topic archived. No new replies allowed.