#include <stdio.h>
#include <stdlib.h>
#include "list.h"
List* create_list() //creates and allocates memory for an empty list.
{
List* L = (List)malloc(sizeof(List));
L->head = NULL;
L->tail = NULL;
return(L);
}
Node create_node(int key) //creates a node with a key and allocates memory for it.
{
Node* N = (Node)malloc(sizeof(Node));
N->key = key;
N->next = NULL;
N->prev = NULL;
return(N);
}
int isEmpty(List L)
{
return L->head == NULL; //If there is no head, the list is empty and it will either return 1 or 0
}
void insert(List* L, Node* N) //Inserts a node into a list.
{
if (L->head != NULL) //If there is no head set the node N to head
{
L->head->prev = N;
}
if (L->tail == NULL) //And if there is no tail set N to tail
{
L->tail = N;
}
N->next = L->head;
N->prev = NULL;
L->head = N;
}
Node* search(const List* L, int key) //Searching for a node using its key.
{
Node* temp_pointer = L->head;
while (temp_pointer != NULL)
{
if (temp_pointer->key == key) //checking if the nodes key matches the searched key.
{
break;
}
temp_pointer = temp_pointer->next;
}
return(temp_pointer);
}
Node* node_delete(List* L, Node* N) //removes a node from the list and returns it
{
if(N->prev != NULL)
{
N->prev->next = N->next; //makes the previous node point to the next from where it's currently at.
}
else
{
L->head = N->next; //if the previous is NULL set the one it's currently at to head
}
if (N->next != NULL)
{
N->next->prev = N->prev; //the next node will now point to the previous one from where it's currently at.
}
if (L->tail == N)
{
L->tail = N->prev; //keeping the tail up to date
}
return(N);
}
Node* maximum(List* L) //Searching for the node with the highest "key" value by comparing every key to the previous one, saving the largest
{
Node* temp_pointer = L->head,max = L->head;
while (temp_pointer!= NULL)
{
if (temp_pointer->key > max->key) //if the temp key is larger than the previous max set max to that temp node
{
max = temp_pointer;
}
temp_pointer = temp_pointer->next;
}
return(max);
}
Node minimum(List* L) //Same as maximum except searching for the minimum
{
Node* temp_pointer = L->head, *min = L->head;
while (temp_pointer != NULL)
{
if (temp_pointer->key < min->key)
{
min = temp_pointer;
}
temp_pointer = temp_pointer->next;
}
return(min);
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}