Skip to content

Instantly share code, notes, and snippets.

@jvanbaarsen
Created June 5, 2013 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvanbaarsen/5715740 to your computer and use it in GitHub Desktop.
Save jvanbaarsen/5715740 to your computer and use it in GitHub Desktop.
#include "linkedlist.h"
linked_list create_list() {
linked_list list;
list = malloc (sizeof (struct linked_list));
if (list == NULL) {
//Something weird happend.. We should catch it
exit(-1);
}
list->first = list->last = NULL;
list->size = 0;
return list;
}
void add_item_to_list(linked_list list, node item) {
//Should add the item to the list
item->next = NULL;
if(list->last) {
item->prev = list->last;
list->last->next = item;
list->last = item;
} else {
list->first = list->last = item;
}
list->size += 1;
}
node pop_item_from_list(linked_list list) {
node item;
if(list->last) {
item = list->last;
}
}
void remove_item_from_list(linked_list list, node item) {
if(item->next) {
} else { //Item is at the end
if(list->first == item) {
list->first = NULL;
}
list->last = NULL;
free(item);
}
}
int has_item_in_list(linked_list list, int entry) {
if(true) {
return 1;
} else {
return 0;
}
}
node get_item_from_list(linked_list list, item) {
if(has_item_in_list(list, item) == 1) {
//Find the item in the list
} else {
exit(-2); // No item error
}
}
void destroy_list(list) {
//Free up all memory
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment