A set of abstract data types.
ADT_List *ADT_list_new(data)
void ADT_list_insert(ADT_List *list, void *data)
void *ADT_list_delete(ADT_List *list, void *data)
int ADT_list_size(ADT_List *list)
void ADT_list_destroy(ADT_List * list);
ADT_List *ADT_list_tail(ADT_List *list)
ADT_IS_EMPTY(head)
(macro)ADT_LIST_NEXT(head)
(macro)ADT_LIST_DATA(head)
(macro)
ADT_Stack *ADT_stk_init(void *data)
int *ADT_stk_push(ADT_Stack *stack, void *data)
int *ADT_stk_pop(ADT_Stack *stack)
ADT_Stack *ADT_stk_peek(const ADT_Stack *stack)
void ADT_stk_destroy(ADT_Stack *stack)
int ADT_stk_size(ADT_Stack *stack)
ADT_STACK_IS_EMPTY(s)
(macro)
Linked List
Create a new list
// Create some data
typedef struct data_t {
char *name;
} Data;
Data *data = malloc(sizeof(Data));
data->name = calloc(4, sizeof(char));
strcpy(data->name, "Joe");
// Pass the data to ADT_list_new to return the new head of the
// linked list
ADT_List *head = ADT_list_new(data);
Insert a new item at the tail of the list
// Create the data and then create a new list
ADT_List *head = ADT_list_new(data);
// Pass the head list head reference to ADT_list_insert function
ADT_list_insert(list, data2);
Remove a node from the list at nth position (matched via the data reference)
// Create your `void* data` & insert the data ref into the list with `ADT_list_insert`
ADT_list_insert(list, data);
// Pass the dasta reference to the ADT_list_delete function as a 2nd argument
void *result = ADT_list_delete(list, data);
if (result < 0)
// handle error
int *d1 = 1;
int *d2 = 1;
ADT_List *l = ADT_list_new(d1);
ADT_list_insert(l, d2);
// Get the sum total of nodes in the list
int result = ADT_list_size(l); // returns 2
Checks if the list is empty. The macro will return true if there are no nodes in the list or the list has not yet been initiated.
int *d = 1;
ADT_List *l = ADT_list_new(d);
int result = ADT_IS_EMPTY(l); // returns false
Get the next list node
int *d1 = 1;
int *d2 = 2;
int result;
ADT_List *l = ADT_list_new(d1);
ADT_list_insert(l, d2);
ADT_List *l2 = ADT_LIST_NEXT(l);
ADT_List *l3 = ADT_LIST_NEXT(l2);
Get the current node's data
int *d1 = 1;
ADT_List *l = ADT_list_new(d1);
int result = ADT_LIST_DATA(l);
Detaches each node from the list. This function does not destroy allocated memory assigned to the node's data.
int *d1 = 1;
int *d2 = 2;
int result;
ADT_List *l = ADT_list_new(d1);
ADT_list_insert(l, d2);
ADT_list_destroy(l);
Returns the last node in the list
int *d1 = 1;
int *d2 = 2;
int result;
ADT_List *l = ADT_list_new(d1);
ADT_list_insert(l, d2);
ADT_List *l2 = ADT_LIST_NEXT(l);
ADT_List *tail = ADT_list_tail(l);
Stack
Initiates the last node in the stack. It is the responsibility of the caller to manage the memory of void *data.
int *d1 = 1;
ADT_Stack *s = ADT_stk_init(d1);
Pushes the next node on the stack.
You must initiates the stack by calling the
init(void *data)
first. It is the responsibility
of the caller to manage the memory of void *data.
int *d1 = 1;
int *d2 = 2;
ADT_Stack *s = ADT_stk_init(d1);
int result = ADT_stk_push(s, d2);
Removes the top nod from the stack. The caller must manage the memory of void *data.
char *d0 = calloc(4, sizeof(char));
ADT_Stack *s = ADT_stk_init(d0);
int res1 = ADT_stk_pop(s);
Enables the caller to peek at the top node without popping it off the stack. It returns a reference to the top node.
Detaches each node from the stack. This function does not destroy allocated memory assigned to the node's data.
Returns the size of the stack based on total count of nodes.
Checks if the stack is empty. The macro will return true if there are no nodes in the stack or the stack has not yet been initiated.
int *d = 1;
ADT_Stack *s = ADT_stk_init(d);
int result = ADT_STACK_IS_EMPTY(s); // 0
result = ADT_STACK_IS_EMPTY(NULL); // 1
- joegasewicz - Initial work - @joegasewicz
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
cd into the test
directory then build & run main.c
- you will need to
statically link the adt_tools & dynamically link libcheck
This library uses doxygen to generate inline docs.