Linked List with C
Basic template and methods

Structure

1
struct Node {
2
struct Node* next;
3
int val;
4
};
Copied!

NewNode

1
struct Node* newNode(int value){
2
struct Node* new_node = (struct Node*) malloc (sizeof(struct Node));
3
new_node->val = value;
4
new_node->next = NULL;
5
return new_node;
6
}
Copied!

AddToTail

1
void addToTail(struct Node **root, int value){
2
struct Node* new_node = (struct Node*) malloc (sizeof(struct Node));
3
new_node->val = value;
4
new_node->next = *root;
5
*root = new_node;
6
}
Copied!

Traverse

1
void traverse(struct Node* ref){
2
struct Node* tmp = ref;
3
while(tmp!= NULL){
4
printf("%d\n", tmp->val);
5
tmp = tmp->next;
6
}
7
}
Copied!