I think it is a pointer to a list of pointers to adjlistnode structures
No, it isn't.
AdjMatrix
becomes a type representing a pointer to pointer to struct adjlistnode
As an example it can be used like:
AdjMatrix p = NULL; // p is now a pointer to pointer to struct adjlistnode
The code seems to be for building a linked list and AdjMatrix
seems to be a short hand for referring to a pointer to the head pointer. It could be used like:
void addNode(AdjMatrix pHead, int node, int cost)
{
struct adjlistnode *tmp = malloc(sizeof *tmp);
tmp->node = node;
tmp->cost = cost;
tmp->next = *pHead;
*pHead = tmp;
}
void deleteNode(AdjMatrix pHead)
{
if (*pHead)
{
struct adjlistnode *tmp = *pHead;
*pHead = tmp->next;
free(tmp);
}
}
int main(void) {
struct adjlistnode *head = NULL;
// Add nodes
addNode(&head, 1, 2);
addNode(&head, 3, 4);
addNode(&head, 5, 6);
// ... use the list
// Delete nodes
while(head) deleteNode(&head);
return 0;
}
Notice that typedef
of pointers is often considered bad practice. Instead it would be better to do:
typedef struct adjlistnode {int node; int cost; struct adjlistnode *next;} AdjMatrix;
and use it like:
void addNode(AdjMatrix **pHead, int node, int cost)
to make it clear the pHead
is a pointer to pointer to AdjMatrix