OS1/smallsh/node.c

63 lines
882 B
C
Raw Permalink Normal View History

2023-11-09 03:07:32 -08: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;
}
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;
}
void iterate_nodes(struct node* head, void *func (void*, void*), void* val) {
if(!head)
return;
func(head->data, val);
struct node* temp = head;
while(temp->node) {
temp = temp->node;
func(temp->data, val);
}
}