Wait, sorry, in this code:
1 2 3 4 5 6
|
struct node {
int data;
struct node *next;
}*start = NULL;
struct node *new_node,*current;
|
*start = NULL; - Declared a global variable of type node. “start” is used to refer the starting node of the linked list.
^ because *start is equals to NULL value, right?
start->next - Access the 2nd Node of the linked list. This term contain the address of 2nd node in the linked list. If 2nd node is not present then it will return NULL.
^ I'm confused. When we created the structure of node, was next already pointing to a second node? Or are we simply connecting the start node to a next node, which is technically NULL? So does this mean that *next is also a node, and not a pointer? I thought pointers just pointed (contained the address) to another node??
start->data - It will access “data” field of starting node.
^ It accessed the data field because it's not a type node (and it's an int type), right?
start->next->data - It will access the “data” field of 2nd node.
^ So, from the start node, it will access the data of the second node because the next node is connected to the second node?
current = start->next - Variable “current” will contain the address of 2nd node of the linked list.
^ sort of understood this because of the start->next statement up there. current should now contain an address as specified by start->next.
start = start->next; - After the execution of this statement, 2nd node of the linked list will be called as “starting node” of the linked list.
^ So, technically, start became the "starting node" because we initialized it's value to NULL, and for easy tracking/debugging purposes, we called it start, right? But, I have a question, when the program is first run (and node is created for the first time), where does *next point to and what is its value?
1 2 3 4
|
struct node {
int data;
struct node *next;
}*start = NULL;
|
Using this resource, btw:
http://c4learn.com/tutorials/data-structure/linked-list/terms-used-in-linked-list-concept/