learning-cc4e

Solution to https://cc4e.com/. If you copy these you're not right in the head.
git clone https://kaka.farm/~git/learning-cc4e
Log | Files | Refs

main.c (843B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 
      4 struct lnode {
      5     int value;
      6     struct lnode *next;
      7 };
      8 
      9 struct list {
     10   struct lnode *head;
     11   struct lnode *tail;
     12 };
     13 
     14 int main()
     15 {
     16     void list_add();
     17     void list_dump();
     18     struct lnode * list_find();
     19 
     20     struct list mylist;
     21     struct lnode * mynode;
     22 
     23     mylist.head = NULL;
     24     mylist.tail = NULL;
     25 
     26     list_add(&mylist, 10);
     27     list_add(&mylist, 20);
     28     list_add(&mylist, 30);
     29     list_dump(&mylist);
     30 
     31     list_remove(&mylist, 42);
     32 
     33     list_remove(&mylist, 10);
     34     list_dump(&mylist);
     35 
     36     list_remove(&mylist, 30);
     37     list_dump(&mylist);
     38 
     39     list_add(&mylist, 40);
     40     list_dump(&mylist);
     41 
     42 }
     43 
     44 void list_dump(lst)
     45     struct list *lst;
     46 {
     47     struct lnode *cur;
     48     printf("\nDump:\n");
     49     for(cur=lst->head; cur != NULL; cur=cur->next) {
     50         printf("  %d\n", cur->value);
     51     }
     52 }