Okay Im getting it to work!! This is how the code looks like now:
Code:
#include "stdio.h"
#include "stdlib.h"
typedef struct node
{
struct node *prev;
int value;
struct node *next;
}node_t;
typedef struct list
{
node_t *head;
int size;
node_t *tail;
}list_t;
int IsEmpty(list_t *list)
{
if (list->size == 0)
{
printf("0");
return 0;
}
else
{
printf("1");
return 1;
}
}
list_t *createList(void)
{
list_t *list = malloc(sizeof(*list));
if (list)
{
list->head = NULL;
list->size = 0;
list->tail = NULL;
}
return list;
}
node_t * createNode(int n)
{
node_t *newnode = malloc(sizeof(node_t));
if (!newnode)
{
return NULL;
}
newnode->value = n;
newnode->next = NULL;
newnode->prev = NULL;
return newnode;
}
void printlist(list_t* list)
{
node_t *current = list->head;
while (current != NULL)
{
printf("%d ", current->value);
current = current->next;
}
printf("\n");
}
int insertTail(list_t *list, node_t *node)
{
if (list->head == NULL)
{
list->head = node;
node->next = NULL;
node->prev = NULL;
list->tail = node;
list->size += 1;
return 1;
}
else
{
node->prev = list->tail;
list->tail->next = node;
list->tail = node;
node->next = NULL;
list->size += 1;
return 1;
}
}
int main()
{
list_t *list2;
list2 = createList();
node_t *node1;
node_t *node2;
node_t *node3;
node_t *node4;
node_t *node5;
node1 = createNode(6);
node2 = createNode(7);
node3 = createNode(8);
node4 = createNode(4);
node5 = createNode(9);
insertTail(list2, node1);
insertTail(list2, node2);
insertTail(list2, node3);
insertTail(list2, node4);
insertTail(list2, node5);
printlist(list2);
free(node5);
free(node4);
free(node3);
free(node2);
free(node1);
free(list2);
}