Commit 28bf64eb authored by Chris Müller's avatar Chris Müller

Add item insertion and concatination

parent 5b547677
......@@ -145,6 +145,25 @@ cry_list_prepend(struct CryList* list, pointer data)
}
void
cry_list_insert(struct CryList* list, struct CryPosition* position, pointer data)
{
assert(list != 0);
if(list->head == 0 || position == 0) {
cry_list_append(list, data);
} else {
struct Node* node = cry_malloc(struct Node);
struct Node* pos = cry_cast(struct Node*, position);
pos->prev = node;
node->next = pos;
if(list->head == pos)
list->head = node;
}
}
struct CryPosition*
cry_list_begin(struct CryList* list)
......@@ -267,4 +286,17 @@ cry_list_remove(struct CryList* list, struct CryPosition* position)
}
struct CryList*
cry_list_concat(struct CryList* first, struct CryList* second)
{
assert(first != 0);
assert(second != 0);
first->tail->next = second->head;
second->head->prev = first->tail;
first->tail = second->tail;
second->head = first->head;
return first;
}
......@@ -33,6 +33,7 @@ pointer cry_list_tail(struct CryList* list);
void cry_list_append(struct CryList* list, pointer data);
void cry_list_prepend(struct CryList* list, pointer data);
void cry_list_insert(struct CryList* list, struct CryPosition* position, pointer data);
struct CryPosition* cry_list_begin(struct CryList* list);
struct CryPosition* cry_list_end(struct CryList* list);
......@@ -45,6 +46,8 @@ pointer cry_list_data(struct CryPosition* position);
pointer cry_list_swap(struct CryPosition* position, pointer new_data);
pointer cry_list_remove(struct CryList* list, struct CryPosition* position);
struct CryList* cry_list_concat(struct CryList* first, struct CryList* second);
/*
struct CryList* cry_list_filter(struct CryList* list, cry_predicate_function predicate, pointer context);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment