Example #1
0
SE_Result SE_List_RemoveFront(SE_List* list)
{
	SE_ListNode* p;
    SE_ASSERT(list);
    SE_ASSERT(list->head != NULL);
    SE_ASSERT(list->tail != NULL);
    if(list->size == 0)
        return SE_INVALID;
    p = list->head->next;
    SE_ASSERT(p != NULL);
    if(p == list->tail)
    {
        list->tail = list->head;
        list->head->next = NULL;
    }
    else
    {
        SE_ListNode* next = p->next;
        list->head->next = next;
        next->prev = list->head;
    }
    freeListNode(p);
    list->size--;
    SE_ASSERT(list->size >= 0);
    return SE_VALID;
}
Example #2
0
/****************************************************************************
 * Function: ListDelNode
 *
 *  Description:
 *      Removes a node from the list
 *      The memory for the node is freed but the
 *      the memory for the items are not.
 *  Parameters:
 *      LinkedList *list  - must be valid, non null, pointer to a linked list.
 *      ListNode *dnode - done to delete.
 *  Returns:
 *      The pointer to the item stored in node on success, NULL on failure.
 *  Precondition:
 *      The list has been initialized.
 *****************************************************************************/
void *
ListDelNode( LinkedList * list,
             ListNode * dnode,
             int freeItem )
{
    void *temp;

    assert( list != NULL );
    assert( dnode != &list->head );
    assert( dnode != &list->tail );

    if( ( list == NULL ) ||
            ( dnode == &list->head ) ||
            ( dnode == &list->tail ) || ( dnode == NULL ) ) {
        return NULL;
    }

    temp = dnode->item;
    dnode->prev->next = dnode->next;
    dnode->next->prev = dnode->prev;

    freeListNode( dnode, list );
    list->size--;

    if( freeItem && list->free_func ) {
        list->free_func( temp );
        temp = NULL;
    }

    return temp;
}
Example #3
0
void SE_List_Release(void* l)
{
    SE_List* list = (SE_List*)l;
	SE_ListNode* p;
    SE_ASSERT(l);
    SE_ASSERT(list->head != NULL);
    SE_ASSERT(list->tail != NULL);
    p = list->head;
    while(p != NULL)
    {
        SE_ListNode* next = p->next;
        freeListNode(p);
        p = next;
    }    
    SE_Object_Clear(list, sizeof(SE_List));
}
Example #4
0
SE_Result SE_List_RemoveLast(SE_List* list)
{
	SE_ListNode* p;
    SE_ASSERT(list);
    SE_ASSERT(list->head != NULL);
    SE_ASSERT(list->tail != NULL);
    if(list->size == 0)
        return SE_INVALID;
    p = list->tail;
    list->tail = p->prev;
    list->tail->next = NULL;
    freeListNode(p);
    list->size--;
    SE_ASSERT(list->size >= 0);
    return SE_VALID; 
}
Example #5
0
SE_Result SE_List_RemoveAt(SE_List* list, int index)
{
	SE_ListNode* p;
	SE_ListNode* prev;
	SE_ListNode* next;
	int i;
    SE_ASSERT(list);
    SE_ASSERT(list->head != NULL);
    SE_ASSERT(list->tail != NULL);
    SE_ASSERT(index >= 0 && index < list->size);
    if(index < 0 || index >= list->size)
        return SE_INVALID;
    p = list->head;
    for(i = 0 ; i <= index ; i++)
    {
        p = p->next;
    }
    SE_ASSERT(p != NULL);
    prev = p->prev;
    next = p->next;
    SE_ASSERT(prev != NULL);
    if(next == NULL)
    {
        list->tail = prev;
        prev->next = NULL;
    }
    else
    {
        prev->next = next;
        next->prev = prev;
        p->prev = p->next = NULL;
    }
    freeListNode(p);
    list->size--;
    SE_ASSERT(list->size >= 0);
    return SE_VALID;
}