2
I have the following structure for my dynamic list:
typedef struct DataNode
{
int id;
} DataNode;
typedef struct Node
{
DataNode data;
struct Node *Next;
} Node;
typedef struct List
{
int size;
Node *head;
} List;
For this structure, I have two methods:
Method Create List:
List *CreateList ()
{
List *list = (List*) malloc(sizeof(List));
list->size = 0;
list->head = NULL;
return list;
}
On the line list->head = NULL
, all elements inside the pointer *head
(type Node), will receive the NULL value? The variable id
and the pointer *Next
will receive the value NULL?
Push method:
void Push (List *list, DataNode data01)
{
Node *node = (Node*) malloc (sizeof(Node));
node->data = data01;
node->Next = list->head;
list->head = node;
list->size++;
}
Because the pointer of the next node receives the address of the node itself ( node->Next = list->head;
)? In the next line the node receives the pointer address *node
(node-type) ( list->head = node;
). When he creates the pointer *node
, he is creating the node in the list? And when the pointer *head
receives the address of the pointer *node
, he’s getting the node address?
Thank you.
I think I got a little bit better. Thank you.
– Alex Borges