#include #include #include "doubly.h" struct node *cons(int v, struct node *lst){ struct node *new = malloc(sizeof(struct node)); if(new == NULL){ printf("cons: out of memory sucka\n"); abort(); } new->first = v; new->rest = lst; new->prev = NULL; if(lst != NULL) lst->prev = new; return(new); } void add_after(int v, struct node *nptr){ if(nptr == NULL){ printf("add_after: Cannot be NULL fool!\n"); abort(); } else{ struct node *temp = nptr->rest; nptr->rest = cons(v, temp); nptr->rest->prev = nptr; } } struct node *remove_first(struct node *lst, int key){ if(lst == NULL) return(lst); struct node *temp = lst->rest, *orig = lst; if(lst->first == key){ free(lst); free(orig); if(temp != NULL) temp->prev = NULL; return(temp); } else{ while(temp != NULL){ if(temp->first == key){ lst->rest = temp->rest; if(lst->rest != NULL) lst->rest->prev = lst; free(temp); free(lst); return(orig); } else{ lst = lst->rest; temp = temp->rest; } } } return(orig); }