Ejemplo n.º 1
0
/*
 * Insert <node> just before <before> in list <list>.
 */
void f_listInsert(List *list, ListNode *node, ListNode *before)
{
    assert(list != NULL);
    assert(node != NULL);

    assert(node->next == NULL);
    assert(node->prev == NULL);
    assert(node->list == NULL);

    assert(before == NULL || before->list == list);

    if (before == NULL) {
	f_listAppendTail(list, node);
	return;
    }
    if (before->prev == NULL) {
	f_listInsertHead(list, node);
	return;
    }

    node->next = before;
    node->prev = before->prev;

    before->prev->next = node;
    before->prev = node;

    node->list = list;

    list->length++;
}
Ejemplo n.º 2
0
/*
 * Insert <node> just before <before> in list <list>.
 */
void f_listInsert(List *list, ListNode *node, ListNode *before)
{
    assert(list != NULL);
    assert(node != NULL);

    assert(N(node)->next == NULL);
    assert(N(node)->prev == NULL);
    assert(N(node)->list == NULL);

    assert(before == NULL || N(before)->list == list);

    if (before == NULL) {
	f_listAppendTail(list, node);
	return;
    }
    if (N(before)->prev == NULL) {
	f_listInsertHead(list, node);
	return;
    }

    N(node)->next = N(before);
    N(node)->prev = N(before)->prev;

    N(before)->prev->next = N(node);
    N(before)->prev = N(node);

    N(node)->list = list;

    list->length++;
}
Ejemplo n.º 3
0
/*
 * Append <node> to <after> in list <list>.
 */
void f_listAppend(List *list, ListNode *node, ListNode *after)
{
    assert(list != NULL);
    assert(node != NULL);

    assert(node->next == NULL);
    assert(node->prev == NULL);
    assert(node->list == NULL);

    assert(after == NULL || after->list == list);

    if (after == NULL) {
	f_listInsertHead(list, node);
	return;
    }
    if (after->next == NULL) {
	f_listAppendTail(list, node);
	return;
    }

    node->prev = after;
    node->next = after->next;

    after->next->prev = node;
    after->next = node;

    node->list = list;

    list->length++;
}
Ejemplo n.º 4
0
/*
 * Append <node> to <after> in list <list>.
 */
void f_listAppend(List *list, ListNode *node, ListNode *after)
{
    assert(list != NULL);
    assert(node != NULL);

    assert(N(node)->next == NULL);
    assert(N(node)->prev == NULL);
    assert(N(node)->list == NULL);

    assert(after == NULL || N(after)->list == list);

    if (after == NULL) {
	f_listInsertHead(list, node);
	return;
    }
    if (N(after)->next == NULL) {
	f_listAppendTail(list, node);
	return;
    }

    N(node)->prev = N(after);
    N(node)->next = N(after)->next;

    N(after)->next->prev = N(node);
    N(after)->next = N(node);

    N(node)->list = list;

    list->length++;
}