std_dds (Standard Dynamic Data Structures) is a simple C Library that implements a range of basic dynamic data structures in C.
- Array List
- Linked List
- Doublely Linked List
- Stack
- Queue
- Graph (Adjacency Matrix)
- Graph (Adjacency List)
- Tree
- Binary Search Tree
- Hash Map
Include the std_dds.h
header file to have access to all the data structures:
#include "std_dds.h"
Otherwise, include individual header files for specific data structures:
#include "array_list.h"
#include "stack.h"
Include all needed .h
files in your project's /include
directory, as well as
their corresponding .c
files in your /src
directory.
Within all std_dds functions are optional error and warning messages that
could be useful during debugging. To enable them define STD_DDS_ERROR_MSG
and/or STD_DDS_WARNING_MSG
, defining STD_DDS_WARNING_MSG
automatically
defines STD_DDS_ERROR_MSG
.:
#define STD_DDS_WARNING_MSG
#include "std_dds.h"
...
LinkedListAppend(NULL, NULL);
/** Calling this function like this will now result in
* this warning message printed to stderr output.
* "[Warning] LinkedListAppend failed. LinkedList value is NULL."
**/
Some std_dds functions return STD_DDS_RESULT
which are unsigned int
values
reflecting the result status of the function process. If a function does not
return STD_DDS_RESULT
its return value in the case of a failure will be
specified in its inline documentation (e.g. -1
, NULL
).
A typical pattern for checking the status of std_dds functions should be similar to the following:
ArrayList *list = ArrayListInit(4);
if(list == NULL){
// HANDLE ERROR
}
if(ArrayListAppend(list, value) != STD_DDS_SUCCESS){
// HANDLE ERROR
}
std_dds_utils.h
contains the function PrintResultCode(STD_DDS_RESULT result)
which can be used to print a result code as its string value.
STD_DDS_RESULT result = ArrayListInsertAt(list, index, value);
if(result != STD_DDS_SUCCESS){
PrintResultCode(result);
// HANDLE ERROR
}
The /examples
directory contains an example program for each data structure,
utilising each one of its associated functions.
To build these programs with make
, run the make
command from the root
directory.
The compiled example programs should now be in the /bin/
directory.
STD_DDS_ERROR_MSG
- Enables error messages printed to
stderr
.
- Enables error messages printed to
STD_DDS_WARNING_MSG
- Enables warning messages printed to
stderr
- (Automatically defines
STD_DDS_ERROR_MSG
)
- Enables warning messages printed to
STD_DDS_RESULT
=unsigned int
STD_DDS_SUCCESS
=0
STD_DDS_NULL_PARAM
=100
STD_DDS_OUT_OF_BOUNDS
=200
STD_DDS_NOT_FOUND
=210
STD_DDS_DUPLICATE_VALUE
=300
STD_DDS_MALLOC_FAILED
=1000
STD_DDS_CALLOC_FAILED
=1010
STD_DDS_REALLOC_FAILED
=1020
This project was completed during my completion of the postgraduate subject COMP9024 Data Structures and Algorithms at UNSW.
The course outline for COMP9024 sites the use of the following three books:
- Algorithms in C Parts 1-4 by Robert Sedgewick
- Algorithms in C Part 5 by Robert Sedgewick
- Programming, Problem Solving, and Abstraction in C by Alistar Moffat