Skip to content

Commit

Permalink
Reorder DSCList functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cm-jones committed Apr 25, 2024
1 parent 830506f commit f2c05f9
Showing 1 changed file with 46 additions and 33 deletions.
79 changes: 46 additions & 33 deletions include/dsc_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
#include <stdbool.h>
#include <stddef.h>

// Forward declaration of the list structure
/* Forward declaration of the list structure */
typedef struct DSCList *DSCList;

/* Constructor and destructor */

/**
* @brief Creates a new list.
*
Expand All @@ -35,10 +37,48 @@ DSCList dsc_list_init(void);
* @brief Destroys the list and frees its memory.
*
* @param list The list to destroy.
*
* @return true if the list was destroyed successfully, false otherwise.
*/
bool dsc_list_deinit(DSCList list);

/* Capacity */

/**
* @brief Gets the size of the list.
*
* @param list The list to get the size of.
* @return The size of the list, or -1 if the list is NULL.
*/
int dsc_list_size(const DSCList list);

/**
* @brief Checks if the list is empty.
*
* @param list The list to check.
* @return true if the list is empty or NULL, false otherwise.
*/
bool dsc_list_is_empty(const DSCList list);

/* Element access */

/**
* @brief Retrieves the value of the first element in the list.
*
* @param list The list to get the first element from.
*
* @return The value of the front element, or -1 if the list is empty or NULL.
*/
int dsc_list_get_head(const DSCList list);

/**
* @brief Retrieves the value of the last element in the list.
*
* @param list The list to get the last element from.
* @return The value of the last element, or -1 if the list is empty or NULL.
*/
int dsc_list_get_tail(const DSCList list);

/**
* @brief Inserts a value at the beginning of the list.
*
Expand All @@ -54,6 +94,7 @@ bool dsc_list_push_front(DSCList list, int value);
*
* @param list The list to insert the value into.
* @param value The value to insert.
*
* @return true if the value was inserted successfully, false otherwise.
*/
bool dsc_list_push_back(DSCList list, int value);
Expand All @@ -64,6 +105,7 @@ bool dsc_list_push_back(DSCList list, int value);
* @param list The list to insert the value into.
* @param value The value to insert.
* @param position The position at which to insert the value.
*
* @return true if the value was inserted successfully, false otherwise.
*/
bool dsc_list_insert(DSCList list, int value, int position);
Expand All @@ -72,6 +114,7 @@ bool dsc_list_insert(DSCList list, int value, int position);
* @brief Removes the first node from the list.
*
* @param list The list to remove the first node from.
*
* @return The popped value, -1 on failure.
*/
int dsc_list_pop_front(DSCList list);
Expand All @@ -81,6 +124,7 @@ int dsc_list_pop_front(DSCList list);
*
* @param list The list to remove the value from.
* @param value The value to remove.
*
* @return true if the value was removed successfully, false otherwise.
*/
bool dsc_list_remove(DSCList list, int value);
Expand All @@ -90,40 +134,9 @@ bool dsc_list_remove(DSCList list, int value);
*
* @param list The list to remove the values from.
* @param value The value to remove.
*
* @return true if the values were removed successfully, false otherwise.
*/
bool dsc_list_remove_all(DSCList list, int value);

/**
* @brief Retrieves the value of the first element in the list.
*
* @param list The list to get the first element from.
* @return The value of the front element, or -1 if the list is empty or NULL.
*/
int dsc_list_get_head(const DSCList list);

/**
* @brief Retrieves the value of the last element in the list.
*
* @param list The list to get the last element from.
* @return The value of the last element, or -1 if the list is empty or NULL.
*/
int dsc_list_get_tail(const DSCList list);

/**
* @brief Gets the size of the list.
*
* @param list The list to get the size of.
* @return The size of the list, or -1 if the list is NULL.
*/
int dsc_list_size(const DSCList list);

/**
* @brief Checks if the list is empty.
*
* @param list The list to check.
* @return true if the list is empty or NULL, false otherwise.
*/
bool dsc_list_is_empty(const DSCList list);

#endif // __DSC_LIST_H__

0 comments on commit f2c05f9

Please sign in to comment.