Linked Lists Question Tres

TL;DR NODES WITH MORE THAN JUST ONE VAR + POINTER TO NEXT NODE?





So right now I've learned that linked lists consist of nodes that interconnect each to another. A node has a piece of data with a pointer that points to another node, or in some cases, null. What I was thinking may sound like a stupid question but.....




Can it be more than just one variable + pointer? Can it be a couple variables AND a pointer to the next?

Just saying. That'd be pretty sweet if it works like that.
Last edited on
Absolutely! Usually a link list contains a structure of several types and a pointer to the next node, or the pointer points to NULL to indicate the end of the linked list:

1
2
3
4
5
6
7
8
9

struct Person
    {
    char LastName[ 50 ];
    char FirstName[ 50 ];
    struct Person* Next;
    };

Do you mean this? Yes, it's legal.

1
2
3
4
5
6
7
8
9
10
11
class Node
{
public:
    ...

private:
    int data 1;
    int data 2;

    Node* next;
};
This. Is. Awesome.
Topic archived. No new replies allowed.