feat: Demo-Examples (Python/Rust/Go/C) mit Protokoll-Templates und Restore-Skript
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
fb4e96919a
commit
64c2b7f0fd
21 changed files with 614 additions and 0 deletions
43
examples/c-linkedlist/linked_list.c
Normal file
43
examples/c-linkedlist/linked_list.c
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "linked_list.h"
|
||||
|
||||
Node *node_new(int value) {
|
||||
Node *n = malloc(sizeof(Node));
|
||||
n->value = value;
|
||||
n->next = NULL;
|
||||
return n;
|
||||
}
|
||||
|
||||
Node *list_prepend(Node *head, int value) {
|
||||
Node *n = node_new(value);
|
||||
n->next = head;
|
||||
return n;
|
||||
}
|
||||
|
||||
Node *list_append(Node *head, int value) {
|
||||
Node *n = node_new(value);
|
||||
if (!head) return n;
|
||||
Node *cur = head;
|
||||
while (cur->next) cur = cur->next;
|
||||
cur->next = n;
|
||||
return head;
|
||||
}
|
||||
|
||||
void list_print(const Node *head) {
|
||||
for (const Node *cur = head; cur; cur = cur->next)
|
||||
printf("%d ", cur->value);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/* BUG: Speicher wird nicht freigegeben — valgrind meldet Leaks. */
|
||||
void list_free(Node *head) {
|
||||
(void)head; /* TODO: implementieren */
|
||||
}
|
||||
|
||||
int list_length(const Node *head) {
|
||||
int len = 0;
|
||||
for (const Node *cur = head; cur; cur = cur->next)
|
||||
len++;
|
||||
return len;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue