Commit f6ad9619 authored by Chris Müller's avatar Chris Müller

Add append and prepend calls for struct CryLists.

parent 169b2846
......@@ -72,7 +72,7 @@ cry_list_head(struct CryList* list)
{
assert(list != 0);
return list->head;
return (list->head != 0) ? list->head->data : 0;
}
......@@ -82,6 +82,47 @@ cry_list_tail(struct CryList* list)
{
assert(list != 0);
return list->tail;
return (list->tail != 0) ? list->tail->data : 0;
}
void
cry_list_append(struct CryList* list, pointer data)
{
assert(list != 0);
struct Node* node = cry_malloc(struct Node);
node->prev = list->tail;
node->next = 0;
node->data = data;
if(list->head != 0)
list->tail->next = node;
else
list->head = node;
list->tail = node;
}
void
cry_list_prepend(struct CryList* list, pointer data)
{
assert(list != 0);
struct Node* node = cry_malloc(struct Node);
node->next = list->head;
node->prev = 0;
node->data = data;
if(list->head != 0)
list->head->prev = node;
else
list->tail = node;
list->head = node;
}
......@@ -12,4 +12,7 @@ size_t cry_list_size(struct CryList* list);
pointer cry_list_head(struct CryList* list);
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);
#endif // CRYSTAL_STRUCTURES_LIST_H
......@@ -4,5 +4,6 @@
#include <standard.h>
typedef void (*cry_free_handler)(pointer data);
typedef int (*cry_item_handler)(pointer data);
#endif // CRYSTAL_STRUCTURES_H
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