summaryrefslogtreecommitdiff
path: root/anim/tools/list.c
diff options
context:
space:
mode:
Diffstat (limited to 'anim/tools/list.c')
-rw-r--r--anim/tools/list.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/anim/tools/list.c b/anim/tools/list.c
new file mode 100644
index 0000000..99836c5
--- /dev/null
+++ b/anim/tools/list.c
@@ -0,0 +1,44 @@
+#include <stdlib.h>
+
+typedef struct node {
+ long value;
+ struct node *next;
+} node;
+
+node *head;
+
+void push(long value) {
+ node *n = malloc(sizeof *n);
+ n->value = value;
+ n->next = head;
+ head = n;
+}
+
+void reverse(void) {
+ node *prev = NULL;
+ node *cur = head;
+ while (cur) {
+ node *next = cur->next;
+ cur->next = prev;
+ prev = cur;
+ cur = next;
+ }
+ head = prev;
+}
+
+void clear(void) {
+ while (head) {
+ node *n = head;
+ head = n->next;
+ free(n);
+ }
+}
+
+int main(void) {
+ push(7);
+ push(12);
+ push(9);
+ reverse();
+ clear();
+ return 0;
+}