-
Brandon Rodriguez authored5ea3caab
LinkedList.c 1.28 KiB
/**
* Brandon Rodriguez
* CS 3240
* 10-04-16
*/
/**
* Standard linked list, in C.
*/
// Import headers.
#include "apue.h"
#include "HelperHeader.h"
#include "LinkedList.h"
/**
* Creates a new node with provided data.
*/
directory_node* create_node(char* absolute_path) {
directory_node* new_node = calloc(1, sizeof(node_t));
new_node->absolute_path = copy_string(absolute_path);
return new_node;
}
/**
* Enqueues node from tail of list.
*
* Return: 1 on success or 0 on failure.
*/
int enqueue_node(char* absolute_path) {
directory_node* a_node = create_node(absolute_path);
if (a_node == NULL) {
return 0;
}
// Check if directories already exist within queue.
if (head_node == NULL) {
head_node = a_node;
tail_node = a_node;
} else {
tail_node->next_node = a_node;
tail_node = a_node;
}
return 1;
}
/**
* Dequeues node from head of list.
*
* Return: Noded on success or null on failure.
*/
directory_node* dequeue_node() {
directory_node* a_node;
// Check that there are nodes to return.
if (head_node == NULL) {
return NULL;
}
// Return current head node.
a_node = head_node;
head_node = head_node->next_node;
a_node->next_node = NULL;
return a_node;
}