Skip to content

Instantly share code, notes, and snippets.

@mopp
Last active December 17, 2020 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mopp/4fb2a0aea78898aab75fc7a1094e8f77 to your computer and use it in GitHub Desktop.
Save mopp/4fb2a0aea78898aab75fc7a1094e8f77 to your computer and use it in GitHub Desktop.
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct list List;
typedef uint8_t Value;
struct list {
List* next;
Value value;
};
List* list_insert(List* t, Value v) {
// 作成
List* new = malloc(sizeof(List));
new->next = NULL;
new->value = v;
// 連結
t->next = new;
return new;
}
int main(int argc, char* argv[]) {
// 作成
List root = {.next = NULL, .value = 0};
List* list1 = list_insert(&root, 1);
List* list2 = list_insert(list1, 1);
List* list3 = list_insert(list2, 1);
// 参照
for (List const* n = root.next; n != NULL; n = n->next) {
printf("%u\n", n->value);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment