IRCWebHooks
Barry Adding files 3f04e22 (4 years, 1 month ago)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include "list.h"
#include "irc.h"
/* Insert first item */
void
insert_first(char *data)
{
struct Node *link = (struct Node*) malloc(sizeof(struct Node));
strcpy(link->data, data);
link->next = head;
head = link;
}
/* Delete the first item */
struct Node *
delete_first(void)
{
struct Node *tempLink = head;
head = head->next;
free(tempLink);
return tempLink;
}
/* Check if list is empty */
bool
is_empty(void)
{
return head == NULL;
}
int
length(void)
{
int length = 0;
struct Node *current;
for(current = head; current != NULL; current = current->next) {
length++;
}
return length;
}
/* Find Node with data */
struct Node *
find(char *data)
{
struct Node* current = head;
if (head == NULL) {
return NULL;
}
while (strncmp(current->data, data, strlen(data))) {
if (current->next == NULL) {
return NULL;
} else {
current = current->next;
}
}
return current;
}
/* Delete a Node */
struct Node *
delete(char *data)
{
struct Node* current = head;
struct Node* previous = NULL;
if (head == NULL) {
return NULL;
}
while (strncmp(current->data, data, strlen(data))) {
if(current->next == NULL) {
return NULL;
} else {
previous = current;
current = current->next;
}
}
if (current == head) {
head = head->next;
} else {
previous->next = current->next;
}
free(current);
return current;
}