2023-10-12 14:25:48 -07:00
|
|
|
|
|
|
|
#include "node.h"
|
|
|
|
|
|
|
|
void append_node(struct node* head, struct node* node_app) {
|
|
|
|
|
|
|
|
if(!head) {
|
|
|
|
head = node_app;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct node* temp = head;
|
|
|
|
|
|
|
|
while(temp->node != NULL) {
|
|
|
|
temp = temp->node;
|
|
|
|
}
|
|
|
|
temp->node = node_app;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
struct node* appendv_node(struct node* head, void* data) {
|
|
|
|
|
|
|
|
struct node* node = malloc(sizeof(struct node));
|
|
|
|
node->data = data;
|
|
|
|
node->node = NULL;
|
|
|
|
|
|
|
|
append_node(head, node);
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2023-10-13 01:39:26 -07:00
|
|
|
int count_nodes(struct node* head) {
|
|
|
|
|
|
|
|
int num = 1;
|
|
|
|
|
|
|
|
if(!head)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
struct node* temp = head;
|
|
|
|
while(temp->node) {
|
|
|
|
|
|
|
|
temp = temp->node;
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2023-10-13 03:29:13 -07:00
|
|
|
void iterate_nodes(struct node* head, void *func (void*, void*), void* val) {
|
|
|
|
|
|
|
|
if(!head)
|
|
|
|
return;
|
|
|
|
|
2023-10-15 15:55:30 -07:00
|
|
|
func(head->data, val);
|
2023-10-13 03:29:13 -07:00
|
|
|
|
|
|
|
struct node* temp = head;
|
|
|
|
|
|
|
|
while(temp->node) {
|
|
|
|
temp = temp->node;
|
|
|
|
func(temp->data, val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|