declared why2_remove_back function
removes last element so this is 1000th commit! Woah... i gone nuts idk... 860917976483233792
This commit is contained in:
parent
3eaba0e0c4
commit
acee29c374
@ -27,6 +27,7 @@ typedef struct _why2_node
|
||||
|
||||
void why2_push(why2_node_t *llist_head, void *value); //PUSH ELEMENT TO LIST BACK
|
||||
void why2_remove(why2_node_t *llist_head, why2_node_t *node); //REMOVE ELEMENT
|
||||
void why2_remove_back(why2_node_t *llist_head); //REMOVE LAST ELEMENT
|
||||
why2_node_t *why2_find(why2_node_t *llist_head, void *value); //FIND ELEMENT IN LIST
|
||||
|
||||
#endif
|
@ -78,6 +78,30 @@ void why2_remove(why2_node_t *llist_head, why2_node_t *node)
|
||||
free(node);
|
||||
}
|
||||
|
||||
void why2_remove_back(why2_node_t *llist_head)
|
||||
{
|
||||
if (llist_head == NULL) return; //EMPTY LIST
|
||||
|
||||
why2_node_t *buffer = llist_head;
|
||||
why2_node_t *deallocating_node;
|
||||
|
||||
if (buffer -> next == NULL) //ONLY ONE NODE
|
||||
{
|
||||
deallocating_node = buffer;
|
||||
|
||||
llist_head = NULL;
|
||||
} else
|
||||
{
|
||||
while (buffer -> next -> next != NULL) buffer = buffer -> next; //GO TO THE NODE BEFORE END
|
||||
|
||||
deallocating_node = buffer -> next;
|
||||
|
||||
buffer -> next = NULL; //UNLINK
|
||||
}
|
||||
|
||||
free(deallocating_node);
|
||||
}
|
||||
|
||||
why2_node_t *why2_find(why2_node_t *llist_head, void *value)
|
||||
{
|
||||
if (llist_head == NULL) return NULL; //EMPTY LIST
|
||||
|
Loading…
x
Reference in New Issue
Block a user