This commit is contained in:
parent
4eeccffc46
commit
263cb19258
2 changed files with 30 additions and 4 deletions
|
@ -7,6 +7,15 @@
|
||||||
#define ANSI_COLOR_RED "\x1b[31m"
|
#define ANSI_COLOR_RED "\x1b[31m"
|
||||||
#define ANSI_COLOR_RESET "\x1b[0m"
|
#define ANSI_COLOR_RESET "\x1b[0m"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Assert a condition
|
||||||
|
* @details If the condition is false, print an error message
|
||||||
|
* and exit the program
|
||||||
|
*
|
||||||
|
* @param condition The condition to assert
|
||||||
|
* @param message The message to print if the condition is false
|
||||||
|
* @return 0 if the condition is true
|
||||||
|
*/
|
||||||
int assert(bool condition, const char *message) {
|
int assert(bool condition, const char *message) {
|
||||||
if (!condition) {
|
if (!condition) {
|
||||||
printf(ANSI_COLOR_RED "Assertion failed: %s\n" ANSI_COLOR_RESET, message);
|
printf(ANSI_COLOR_RED "Assertion failed: %s\n" ANSI_COLOR_RESET, message);
|
||||||
|
|
25
src/tree.h
25
src/tree.h
|
@ -5,20 +5,37 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
// A regular node with a left and right branch
|
/**
|
||||||
|
* @brief A node in a binary tree
|
||||||
|
* @details A node in a binary tree has some data
|
||||||
|
* and can have a left and right branch
|
||||||
|
*/
|
||||||
struct Node {
|
struct Node {
|
||||||
|
/** @brief The data of the node */
|
||||||
int data;
|
int data;
|
||||||
struct Node *left, *right;
|
|
||||||
|
/** @see Node */
|
||||||
|
struct Node *left;
|
||||||
|
|
||||||
|
/** @see Node */
|
||||||
|
struct Node *right;
|
||||||
};
|
};
|
||||||
typedef struct Node Node;
|
typedef struct Node Node;
|
||||||
|
|
||||||
// Represents a tree with a root node
|
/** @brief Represents a tree with a root node */
|
||||||
struct Tree {
|
struct Tree {
|
||||||
|
/** @brief The root node of the tree */
|
||||||
Node *root;
|
Node *root;
|
||||||
};
|
};
|
||||||
typedef struct Tree Tree;
|
typedef struct Tree Tree;
|
||||||
|
|
||||||
// Insert some data into the tree
|
/**
|
||||||
|
* @brief Insert some data into the tree
|
||||||
|
*
|
||||||
|
* @param tree
|
||||||
|
* @param data
|
||||||
|
* @return * Insert
|
||||||
|
*/
|
||||||
int tree_insert(Tree *tree, int data);
|
int tree_insert(Tree *tree, int data);
|
||||||
|
|
||||||
// Remove some data from the tree
|
// Remove some data from the tree
|
||||||
|
|
Loading…
Reference in a new issue