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.
eon/linked_list/linked_list.c

68 lines
1.5 KiB

#include <stdlib.h>
#include "linked_list.h"
/**
* free's a linked list
* @param head of linked list to be freed
* @return void
*/
void _free_linked_list(node_info *p_list) {
node_info *temp;
while(p_list->next) {
temp = p_list;
p_list = p_list->next;
free(temp);
}
}
/**
* returns a copy of list
* @param nodeInfo list to be copied
* @return copied list
*/
node_info *copy_linked_list(node_info *p_list) {
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;
copy_list = copy_list->next;
}
return new_list;
}
/*
@return void
@param node_info* (head of linked list)
@param node_info* (node to add)
Adds link to linked list.
*/
void linked_list_add(node_info* p_head, node_info* new_node)
{
node_info* p_head_temp = p_head;
while (p_head->next)
p_head_temp = p_head_temp->next;
p_head_temp->next = p_head;
}
/*
@return bool (removed or not)
@param node_info* (head of linked list)
@param node_info* (node to delete from linked list)
*/
bool linked_list_remove(node_info* p_head, node_info* delete_node)
{
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;
}