#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "DLinkedList.h"
void AddWord(struct List *l, char *w)
{
if (l->head == NULL)
{
printf("No head node, creating one\n");
struct ListNode *tmp = (struct ListNode *)malloc(sizeof(struct ListNode));
l->head = tmp;
l->tail = tmp;
tmp->previous = l->head;
tmp->next = l->tail;
tmp->data = (char *)malloc(strlen(w) + 1);
strcpy(tmp->data, w);
tmp->data[strlen(w)] = '\0';
return;
}
printf("Creating Node\n");
struct ListNode *tmp = l->tail;
tmp->next = (struct ListNode *)malloc(sizeof(struct ListNode));
tmp->next->previous = tmp;
l->tail = tmp->next;
tmp->next->next = l->tail;
tmp->next->data = (char *)malloc(strlen(w) + 1);
strcpy(tmp->next->data, w);
tmp->next->data[strlen(w)] = '\0';
return;
}
void PrintList(struct List *l)
{
struct ListNode *tmp = l->head;
for(;;)
{
if (tmp == l->tail)
{
printf("%s\n", tmp->data);
break;
}
printf("%s\n", tmp->data);
tmp = tmp->next;
}
}
void DeleteList(struct List *l)
{
struct ListNode *tmp = l->head;
for(;;)
{
if (tmp == l->tail)
{
free(tmp->data);
free(tmp);
return;
}
free(tmp->data);
tmp = tmp->next;
free(tmp->previous);
}
l->head = NULL;
l->tail = NULL;
}