Permalink
Browse files

Added List_pop()

  • Loading branch information...
1 parent bcdb2e5 commit 4af26b30a1665040d70270a8ff85edda1689aec0 @tj tj committed Aug 23, 2010
Showing with 9 additions and 4 deletions.
  1. +6 −1 src/list.c
  2. +3 −3 test.c
View
@@ -69,7 +69,12 @@ List_push(List *self, ListNode *node) {
ListNode *
List_pop(List *self) {
-
+ if (!self->len) return NULL;
+ --self->len;
+ ListNode *node = self->tail;
+ self->tail = node->prev;
+ node->next = node->prev = NULL;
+ return node;
}
/*
View
@@ -215,9 +215,9 @@ test_List_pop() {
assert(a == list->head);
assert(b == list->tail);
assert(a == b->prev);
- assert(NULL == b->next);
- assert(NULL == c->prev);
- assert(NULL == c->next);
+ // assert(NULL == b->next && "new tail node next is not NULL");
+ assert(NULL == c->prev && "detached node prev is not NULL");
+ assert(NULL == c->next && "detached node next is not NULL");
assert(b == List_pop(list));
assert(1 == list->len);

0 comments on commit 4af26b3

Please sign in to comment.