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

solution.c (691B)


      1 void list_add(lst, value)
      2     struct list *lst;
      3     int value;
      4 {
      5   struct lnode *new_node = (
      6     (struct lnode *)
      7     malloc(sizeof(struct lnode))
      8   );
      9   new_node->value = value;
     10   new_node->next = NULL;
     11 
     12   if (lst->head == NULL) {
     13     lst->head = new_node;
     14   }
     15   if (lst->tail == NULL) {
     16     lst->tail = new_node;
     17   } else {
     18     lst->tail->next = new_node;
     19     lst->tail = new_node;
     20   }
     21 }
     22 
     23 struct lnode * list_find(lst, value)
     24     struct list *lst;
     25     int value;
     26 {
     27   struct lnode *node_walker;
     28   for (node_walker = lst->head;
     29        node_walker != NULL;
     30        node_walker = node_walker->next) {
     31     if (node_walker->value == value) {
     32       return node_walker;
     33     }
     34   }
     35   return NULL;
     36 }