see LinkedList.c More...
Go to the source code of this file.
Data Structures | |
struct | LinkedList |
Stores a linked list, with sentinel links for head and tail. These sentinels contain dummy values. More... | |
struct | Link |
Stores data and pointers to next and previous links. More... | |
Typedefs | |
typedef struct Link | Link |
typedef struct LinkedList | LinkedList |
Functions | |
int | isHead (Link *list) |
tells if a given Link is the head sentinel. | |
int | isTail (Link *list) |
tells if a given Link is the tail sentinel. | |
void * | delete (Link *list) |
delete the given link, and return its data. | |
Link * | addAfter (Link *list, void *data) |
location-aware function to add a link after a given link. | |
Link * | addBefore (Link *list, void *data) |
location-aware function to add a link before a given link. | |
void | addLinkBefore (Link *list, Link *newLink) |
location-aware method to add a link before another link. | |
Link * | removeLink (Link *list) |
location-aware method to remove a link, and return it. | |
LinkedList * | createLinkedList (void) |
create a new empty linked list | |
void | destroyLinkedList (LinkedList *linkedList) |
destroy a linked list | |
void | copyLinkedList (LinkedList *destination, LinkedList *source) |
copy a linked list | |
int | contains (LinkedList *linkedList, void *data, int(*comparator)(void *, void *)) |
decide if a linked list contains a piece of data. | |
int | equal (LinkedList *list1, LinkedList *list2, int(*comparator)(void *, void *)) |
Compare two linked lists to see if they are equal. | |
void | restoreLinksWithReferences (LinkedList *list) |
Link * | addFirst (LinkedList *linkedList, void *data) |
A location-aware function to add data to the beginning of a linked list. | |
Link * | addLast (LinkedList *linkedList, void *data) |
A location-aware function to add data to the end of a linked list. | |
Link * | removeFirst (LinkedList *linkedList) |
remove the first link from a linked list | |
Link * | removeLast (LinkedList *linkedList) |
Remove and return the last link from a linked list. | |
void | deleteLast (LinkedList *linkedList) |
delete the last link in the linked list | |
void * | getFirst (LinkedList *linkedList) |
return the first piece of data in a linked list | |
void | printListAbbv (LinkedList *linkedList, void(*printFunc)(void *)) |
Print the first 10 items in the linked list. | |
void | printList (LinkedList *linkedList, void(*printFunc)(void *)) |
Print the items in the linked list. | |
int | length (LinkedList *linkedList) |
Compute the number of data elements in a linked list. | |
int | isEmpty (LinkedList *linkedList) |
Determine if a linked list is empty. |
see LinkedList.c
Copyright (c) 2011 Darren Strash. This code is released under the GNU Public License (GPL) 3.0.
typedef struct LinkedList LinkedList |
location-aware function to add a link after a given link.
list | The link that we want to add our data after. | |
data | A peice of data to put in the added link. |
location-aware function to add a link before a given link.
list | The link that we want to add our data before. | |
data | A peice of data to put in the added link. |
Link* addFirst | ( | LinkedList * | linkedList, | |
void * | data | |||
) |
A location-aware function to add data to the beginning of a linked list.
linkedList | A linked list. | |
data | The data that we want to add to the beginning of linkedList. |
Link* addLast | ( | LinkedList * | linkedList, | |
void * | data | |||
) |
A location-aware function to add data to the end of a linked list.
linkedList | A linked list. | |
data | The data that we want to add to the end of linkedList. |
location-aware method to add a link before another link.
list | The link that we want to add a link before. | |
newLink | The Link to be added after list. |
int contains | ( | LinkedList * | linkedList, | |
void * | data, | |||
int(*)(void *, void *) | comparator | |||
) |
decide if a linked list contains a piece of data.
linkedList | A linked list. | |
data | The data that we want to look for in linkedList. | |
comparator | A function that returns 0 when two data elements are equal. |
void copyLinkedList | ( | LinkedList * | destination, | |
LinkedList * | source | |||
) |
copy a linked list
destination | copy the linked list here | |
source | copy this linked list |
LinkedList* createLinkedList | ( | void | ) |
create a new empty linked list
void* delete | ( | Link * | list | ) |
delete the given link, and return its data.
list | The link that we want to get rid of. |
void deleteLast | ( | LinkedList * | linkedList | ) |
delete the last link in the linked list
linkedList | A linked list. |
void destroyLinkedList | ( | LinkedList * | linkedList | ) |
destroy a linked list
If you allocated data that is in each link, then this will cause a memory leak for you.
linkedList | The linked list to destroy. |
int equal | ( | LinkedList * | list1, | |
LinkedList * | list2, | |||
int(*)(void *, void *) | comparator | |||
) |
Compare two linked lists to see if they are equal.
list1 | A linked list. | |
list2 | Another linked list. | |
comparator | A function to compare data in the links copy this linked list. |
void* getFirst | ( | LinkedList * | linkedList | ) |
return the first piece of data in a linked list
linkedList | A linked list. |
int isEmpty | ( | LinkedList * | linkedList | ) |
Determine if a linked list is empty.
linkedList | A linked list. |
int isHead | ( | Link * | list | ) |
tells if a given Link is the head sentinel.
list | A link structure. |
int isTail | ( | Link * | list | ) |
tells if a given Link is the tail sentinel.
list | A link. |
int length | ( | LinkedList * | linkedList | ) |
Compute the number of data elements in a linked list.
linkedList | A linked list. |
void printList | ( | LinkedList * | linkedList, | |
void(*)(void *) | printFunc | |||
) |
Print the items in the linked list.
linkedList | A linked list. | |
printFunc | A function to print the data elements in the linked list. |
void printListAbbv | ( | LinkedList * | linkedList, | |
void(*)(void *) | printFunc | |||
) |
Print the first 10 items in the linked list.
linkedList | A linked list. | |
printFunc | A function to print the data elements in the linked list. |
Link* removeFirst | ( | LinkedList * | linkedList | ) |
remove the first link from a linked list
linkedList | A linked list. |
Link* removeLast | ( | LinkedList * | linkedList | ) |
Remove and return the last link from a linked list.
linkedList | A linked list. |
location-aware method to remove a link, and return it.
list | The link that we want remove and return. |
void restoreLinksWithReferences | ( | LinkedList * | list | ) |