static void test_list_rpop() { // Setup list_t *list = list_new(); list_node_t *a = list_rpush(list, list_node_new("a")); list_node_t *b = list_rpush(list, list_node_new("b")); list_node_t *c = list_rpush(list, list_node_new("c")); // Assertions assert(3 == list->len); assert(c == list_rpop(list)); assert(2 == list->len); assert(a == list->head); assert(b == list->tail); assert(a == b->prev); assert(NULL == list->tail->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_rpop(list)); assert(1 == list->len); assert(a == list->head); assert(a == list->tail); assert(a == list_rpop(list)); assert(0 == list->len); assert(NULL == list->head); assert(NULL == list->tail); assert(NULL == list_rpop(list)); assert(0 == list->len); }
void prc_die(){ Process* prc = prc_getCurrentProcess(); prc->i_should_die = TRUE; // change focus if (currFocusedProc == prc){ list_rpop(stackFocused); currFocusedProc = list_tail(stackFocused)->val; // prevous process should take a screen hw_scr_mapScreenBuffer(currFocusedProc->screen->addr); } prc->sync_lock = FALSE; krn_getIdleProcess()->sync_lock = TRUE; if (prc->exist_canvas == FALSE){ free(prc->screen->addr); free(prc->screen); } free(prc->stack); _mem_destroy(prc->heap); free(prc->heap); krn_getIdleProcess()->sync_lock = FALSE; }
int main(int argc, char *argv[]) { list_t *plist = list_create(); list_rpush(plist, "test"); char* value = list_rpop(plist); if(value) { printf("%s\n", value); list_remove(plist, value); } value = list_rpop(plist); if(value == NULL) { printf("no value!\n"); } list_destroy(&plist); return 0; }
json_value_t * json_array_pop (json_array_t *self) { if (0 == self->list->len) { return NULL; } list_node_t *node = list_rpop(self->list); if (NULL == node) { return NULL; } self->length = self->list->len; return (json_value_t *) node->val; }
void case_list_rpop() { struct list *list = list(); char *s1 = "s1", *s2 = "s2", *s3 = "s3"; assert(list_lpush(list, s1) == LIST_OK); assert(list_lpush(list, s2) == LIST_OK); assert(list_lpush(list, s3) == LIST_OK); assert(list_len(list) == 3); assert(list->tail->data == s1); assert(list_rpop(list) == s1); assert(list_len(list) == 2); assert(list->tail->data == s2); assert(list_rpop(list) == s2); assert(list_len(list) == 1); assert(list->tail->data == s3); assert(list_rpop(list) == s3); assert(list_len(list) == 0); assert(list->tail == NULL); list_free(list); }
void* list_removeFrom(list l, int index) { if (l->len == 0) return 0; list_node n = __list_getNthNode(l, index); if (n == l->HEAD) return list_rpop(l); else if (n == l->TAIL) return list_pop(l); else { __node_remove(n); void* val = n->value; free(n); l->len -= 1; return val; } }