Keeping Linked List Information
The head node
When working with lists, there seem to be certain items of information
about the list that is common. Some of these things are:
- Number of nodes in a list
- A total of some values in the list
- The head of the list
- Sometimes we need to know the tail of the list
- etc.
It is quite common to have another type of struct that holds this
information about the list. It can increase efficiency in the program
by always keeping a total of some data members, etc.
Here's an example:
typedef struct node *NODEPTR;
typedef struct node
{
int data;
NODEPTR next;
}NODE;
/* Struct to keep info about the list */
typedef struct listInfo
{
int numNodes;
int dataTotal;
NODEPTR head;
NODEPTR tail;
} LISTINFO;