Commit 78b9be6a authored by Lenitra's avatar Lenitra
Browse files

push ?

parent 36e733cb
Loading
Loading
Loading
Loading
+16 −18
Changes for src/list.c: 16 added lines, 18 removed lines.
Original line number Diff line number Diff line
@@ -17,20 +17,19 @@ int list_is_empty(list_t l){
}

list_t list_push(list_t l, void *x){
  // add x to the end of l
  list_t c = malloc(sizeof(l));
  c -> val = x;
  if (list_is_empty(l)){
    c -> id = 0;
    c -> next = NULL;
    return c;
  list_t cell = malloc(sizeof(*cell));
  cell->val = x;
  if (list_is_empty(l))
  {
    cell->id = 1;
    cell->next = NULL;
  }
  else {
    c -> id = l -> id + 1;
    c -> next = l;
    return c;
  else
  {
    cell->id = l->id + 1;
    cell->next = l;
  }
  
  return cell;
}

list_t list_tail(list_t l){
@@ -81,12 +80,11 @@ void* list_in(list_t l, void* x, int (*eq)(void*, void*)){
}

unsigned long int list_len(list_t l){
 if (list_is_empty(l)){
   return 0;
 }
 else {
   return l->id + 1;
  unsigned long int len = 0;
  while(!list_is_empty(l)){
    len++;
    l = l->next;
  }
 
  return len;
}