|
|
|
#ifndef LINKED_LIST_C
|
|
|
|
#define LINKED_LIST_C
|
|
|
|
#include "linked_list.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
Author: xerox
|
|
|
|
Update: 1/20/2020
|
|
|
|
|
|
|
|
free's linked list.
|
|
|
|
*/
|
|
|
|
static void free_linked_list(node_info *p_list)
|
|
|
|
{
|
|
|
|
if (!p_list)
|
|
|
|
return;
|
|
|
|
|
|
|
|
node_info* temp;
|
|
|
|
while (p_list->next)
|
|
|
|
{
|
|
|
|
temp = p_list;
|
|
|
|
p_list = p_list->next;
|
|
|
|
free(temp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Author: xerox
|
|
|
|
Update: 5/13/2020
|
|
|
|
|
|
|
|
shallow copy linked list.
|
|
|
|
*/
|
|
|
|
static node_info* shallow_copy_linked_list(node_info* p_list)
|
|
|
|
{
|
|
|
|
if (!p_list)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
node_info* new_list = malloc(sizeof(node_info));
|
|
|
|
new_list->next = NULL;
|
|
|
|
node_info* copy_list = new_list;
|
|
|
|
|
|
|
|
while(p_list->next)
|
|
|
|
{
|
|
|
|
p_list = p_list->next;
|
|
|
|
copy_list->next = p_list;
|
|
|
|
}
|
|
|
|
return new_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Author: xerox
|
|
|
|
Update: 1/20/2020
|
|
|
|
|
|
|
|
append to linked list.
|
|
|
|
*/
|
|
|
|
static void linked_list_append(node_info* p_head, node_info* new_node)
|
|
|
|
{
|
|
|
|
if (!p_head || !new_node)
|
|
|
|
return;
|
|
|
|
|
|
|
|
node_info* p_head_temp = p_head;
|
|
|
|
while (p_head->next)
|
|
|
|
p_head_temp = p_head_temp->next;
|
|
|
|
|
|
|
|
p_head->next = NULL;
|
|
|
|
p_head_temp->next = p_head;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Author: xerox
|
|
|
|
Update: 1/20/2020
|
|
|
|
|
|
|
|
remove link from linked list.
|
|
|
|
*/
|
|
|
|
static bool linked_list_remove(node_info* p_head, node_info* delete_node)
|
|
|
|
{
|
|
|
|
if (!p_head || !delete_node)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
node_info* p_head_temp = p_head;
|
|
|
|
while (p_head_temp->next)
|
|
|
|
{
|
|
|
|
if (p_head_temp->next == delete_node)
|
|
|
|
{
|
|
|
|
p_head_temp->next = delete_node->next;
|
|
|
|
free(delete_node);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|