Esempio n. 1
0
/*---------------------------------------------------------------------------*/
csr_list_result csr_list_remove(csr_list* list, csr_list_node* node)
{
    require(TR_CSR_LIST, list != NULL);
    require(TR_CSR_LIST, node != NULL);
    require(TR_CSR_LIST, isInList(list, node) != NULL); /*lint !e666 */

    if (list->head == node)
    {
        list->head = node->next;
        if (list->head == NULL)
        {
            list->tail = NULL;
        }
        DELETE_NODE(node);
    }
    else
    {
        csr_list_node* prevnode = findPrevNode(list, node);
        if (prevnode == NULL)
        {
            return csr_list_not_found;
        }
        prevnode->next = node->next;
        if (prevnode->next == NULL)
        {
            list->tail = prevnode;
        }
        DELETE_NODE(node);
    }
    list->count--;
    return csr_list_success;
}
Esempio n. 2
0
void practice89(list_t list)
{

	node_t* nodePtr;

	printf("\n값이 40인 노드 삭제하는 함수\n헤드가 없을때까지 계속 헤드를 삭제하는 함수\n\n");
	printf("전체 리스트\n");
	printAllNodes(&list);
	nodePtr = searchNode(&list, 40);
	deleteNode(&list, findPrevNode(&list, nodePtr), nodePtr);
	printf("값이 40인 노드 삭제\n");
	printAllNodes(&list);
	printf("헤드가 없어질때까지 헤드를 삭제\n");
	while (list.head)
	{
		deleteNode(&list, (node_t*)NULL, list.head);
		printAllNodes(&list);
	}

	fflush(stdin);
	getchar();

	return;
}