linked list: add lld_insert_prev/next()
Change-Id: I55ff061ccc0e6e2dad3125a8150c082c163db329
This commit is contained in:
parent
ee9679993b
commit
5e864ecde9
2 changed files with 36 additions and 0 deletions
|
@ -133,6 +133,38 @@ void ll_remove(struct ll_head *list, struct ll_node *node)
|
||||||
|
|
||||||
/** (L)inked (L)ist (D)ouble **/
|
/** (L)inked (L)ist (D)ouble **/
|
||||||
|
|
||||||
|
void lld_insert_next(struct lld_head *list, struct lld_node *node,
|
||||||
|
struct lld_node *newnode)
|
||||||
|
{
|
||||||
|
struct lld_node **nodep = node != NULL ? &node->next : &list->head;
|
||||||
|
struct lld_node *next = *nodep;
|
||||||
|
|
||||||
|
newnode->next = next;
|
||||||
|
newnode->prev = node;
|
||||||
|
*nodep = newnode;
|
||||||
|
|
||||||
|
if (next == NULL)
|
||||||
|
list->tail = newnode;
|
||||||
|
else
|
||||||
|
next->prev = newnode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void lld_insert_prev(struct lld_head *list, struct lld_node *node,
|
||||||
|
struct lld_node *newnode)
|
||||||
|
{
|
||||||
|
struct lld_node **nodep = node != NULL ? &node->prev : &list->tail;
|
||||||
|
struct lld_node *prev = *nodep;
|
||||||
|
|
||||||
|
newnode->next = node;
|
||||||
|
newnode->prev = prev;
|
||||||
|
*nodep = newnode;
|
||||||
|
|
||||||
|
if (prev == NULL)
|
||||||
|
list->head = newnode;
|
||||||
|
else
|
||||||
|
prev->next = newnode;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a node to a doubly-linked list using "insert first"
|
* Adds a node to a doubly-linked list using "insert first"
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -103,6 +103,10 @@ static inline void lld_init(struct lld_head *list)
|
||||||
the routines and maintains the non-circularity */
|
the routines and maintains the non-circularity */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lld_insert_next(struct lld_head *list, struct lld_node *node,
|
||||||
|
struct lld_node *newnode);
|
||||||
|
void lld_insert_prev(struct lld_head *list, struct lld_node *node,
|
||||||
|
struct lld_node *newnode);
|
||||||
void lld_insert_first(struct lld_head *list, struct lld_node *node);
|
void lld_insert_first(struct lld_head *list, struct lld_node *node);
|
||||||
void lld_insert_last(struct lld_head *list, struct lld_node *node);
|
void lld_insert_last(struct lld_head *list, struct lld_node *node);
|
||||||
void lld_remove(struct lld_head *list, struct lld_node *node);
|
void lld_remove(struct lld_head *list, struct lld_node *node);
|
||||||
|
|
Loading…
Reference in a new issue