Provide a new convenience function that adds an element to the beginning
of a list.
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
list->count++;
}
+void listnode_add_head(struct list *list, void *val)
+{
+ struct listnode *node;
+
+ assert(val != NULL);
+
+ node = listnode_new();
+
+ node->next = list->head;
+ node->data = val;
+
+ if (list->head == NULL)
+ list->head = node;
+ else
+ list->head->prev = node;
+ list->head = node;
+
+ list->count++;
+}
+
void listnode_add_sort(struct list *list, void *val)
{
struct listnode *n;
*/
extern void listnode_add(struct list *list, void *data);
+/*
+ * Add a new element to the beginning of a list.
+ *
+ * Runtime is O(1).
+ *
+ * list
+ * list to operate on
+ *
+ * data
+ * element to add
+ */
+extern void listnode_add_head(struct list *list, void *data);
+
/*
* Insert a new element into a list with insertion sort.
*