You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
1.6 KiB

5 years ago
#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;
5 years ago
node_info* temp;
while (p_list->next)
{
temp = p_list;
p_list = p_list->next;
free(temp);
}
}
/*
Author: xerox
Update: 5/13/2020
5 years ago
shallow copy linked list.
5 years ago
*/
static node_info* shallow_copy_linked_list(node_info* p_list)
5 years ago
{
if (!p_list)
5 years ago
return NULL;
node_info* new_list = malloc(sizeof(node_info));
5 years ago
new_list->next = NULL;
node_info* copy_list = new_list;
5 years ago
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;
5 years ago
node_info* p_head_temp = p_head;
while (p_head->next)
p_head_temp = p_head_temp->next;
p_head->next = NULL;
5 years ago
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