AddHead()
function:
void AddHead( List *l, Node *n )
l
argument is a pointer to the list to which to add the node, while the n
argument is a pointer to the node to add.
AddTail()
function:
void AddTail( List *l, Node *n )
l
argument is a pointer to the list to which to add the node, while the n
argument is a pointer to the node to add.
InsertNodeAfter()
function:
void InsertNodeAfter( Node *oldNode, Node *newNode )
oldNode
argument is a pointer to a node already in the list, while the newNode
argument is a pointer to the new node to insert.
InsertNodeBefore()
function:
void InsertNodeBefore( Node *oldNode, Node *newNode )
oldNode
argument is a pointer to a node already in the list, while the newNode
argument is a pointer to the new node to insert.
InsertNodeFromHead()
function:
void InsertNodeFromHead( List *l, Node *n )
l
argument is a pointer to the list to which to add the node, while the n
argument is a pointer to the node to add.
The name InsertNodeFromHead()
refers to the way the kernel traverses the list to find the correct position for a new node: it compares the priority of the new node to the priorities of nodes already in the list, beginning at the head of the list, and inserts the new node immediately after nodes with higher priorities. If the priorities of all the nodes in the list are higher than the priority of the new node, the node is added to the end of the list.
To insert a new node immediately after all other nodes of the same priority, you use the InsertNodeFromTail()
function:
void InsertNodeFromTail( List *l, Node *n )
l
argument is a pointer to the list to which to add the node, while the n
argument is a pointer to the node to add. As with InsertNodeFromHead(),
the name InsertNodeFromTail()
refers to the way the kernel traverses the list to find the correct position for the new node: it compares the priority of the new node to the priorities of nodes already in the list, beginning at the tail of the list, and inserts the new node immediately before nodes with lower priorities. If the priorities of all the nodes in the list are lower, the node is added to the head of the list.
UniversalInsertNode()
function to insert new nodes:
void UniversalInsertNode( List *l, Node *n, bool (*f)(Node *n, Node *m) )
l
argument is a pointer to the list to which to add the node, while the n
argument is a pointer to the node to add. Like InsertNodeFromHead()
, UniversalInsertNode()
compares the node to be inserted with nodes already in the list, beginning with the first node. The difference is that it uses the comparison function f
provided by your task to compare the new node to existing nodes. If the comparison function returns TRUE, the new node is inserted immediately before the node to which it was compared. If the comparison function always returns FALSE, the new node becomes the last node in the list. The comparison function, whose arguments are pointers to two nodes, can use any data in the nodes for the comparison.