Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct List {
- int value;
- struct List *next;
- };
- void insert(struct List **root, int value) {
- if (*root == NULL) {
- *root = (struct List*)malloc(sizeof(struct List));
- (*root)->value = value;
- (*root)->next = NULL;
- } else {
- struct List *tmp = (struct List*)malloc(sizeof(struct List));
- tmp->value = value;
- tmp->next = *root;
- *root = tmp;
- }
- }
- void print(struct List *root) {
- while (root->next != NULL) {
- printf("%d, ", root->value);
- root = root->next;
- }
- printf("%d\n", root->value);
- }
- int main() {
- struct List *list = NULL;
- for (int i = 0; i < 10; i++) {
- insert(&list, i);
- }
- print(list);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement