Refactor tree files, for better readability, and start tree documentation
This commit is contained in:
parent
057648a901
commit
373828db8c
|
@ -0,0 +1,33 @@
|
|||
.DA
|
||||
|
||||
.TL
|
||||
binary_tree.h
|
||||
|
||||
.AU
|
||||
Wael Karram
|
||||
|
||||
.AB no
|
||||
Documentation for binary_tree.h
|
||||
.AE
|
||||
|
||||
.ND
|
||||
|
||||
.PP
|
||||
This header defines a binary tree, with the prepoccessor variable BINARY_TREE_H used as an include guard.
|
||||
.br
|
||||
Includes the struct
|
||||
.UL tree_node_t \0which
|
||||
has the fields
|
||||
.I "left" ,\0
|
||||
.I "right" \0and
|
||||
.I "data" ,
|
||||
the former of which are other node pointers, and the latter is a void pointer.
|
||||
|
||||
.PP
|
||||
This header defines the following functions:
|
||||
.br
|
||||
tree_node_t* initialize_tree_node(): This function initializes an empty tree node, returning the pointer thereof on success and NULL on failure.
|
||||
.br
|
||||
tree_node_t* initialize_tree_node_store(void *data): This function initializes an empty tree node, returning the pointer thereof on success and NULL on failure - stores the given data into the node too.
|
||||
.br
|
||||
int link_tree_node
|
|
@ -2,12 +2,6 @@
|
|||
/* Include statements. */
|
||||
#include "binary_search_tree.h"
|
||||
#include "../binary_tree/binary_tree.c"
|
||||
/* Define the constants. */
|
||||
#define BINARY_SEARCH_TREE_SUCCESS_CODE 0
|
||||
#define BINARY_SEARCH_TREE_FAILURE_CODE 1
|
||||
#define BINARY_SEARCH_TREE_COMPARISON_SMALLER_THAN -1
|
||||
#define BINARY_SEARCH_TREE_COMPARISON_EQUAL_TO 0
|
||||
#define BINARY_SEARCH_TREE_COMPARISON_LARGER_THAN 1
|
||||
|
||||
/* This function initializes a new empty tree node, will return NULL on failure. */
|
||||
tree_node_t* initialize_binary_search_tree_node() {
|
||||
|
|
|
@ -4,6 +4,18 @@
|
|||
#define BINARY_SEARCH_TREE_H
|
||||
#include "../../nodes/tree_node.h"
|
||||
|
||||
/* Define constants. */
|
||||
/* Return code for success. */
|
||||
#define BINARY_SEARCH_TREE_SUCCESS_CODE 0
|
||||
/* Return code for failure. */
|
||||
#define BINARY_SEARCH_TREE_FAILURE_CODE 1
|
||||
/* Return code for comparison, smaller. */
|
||||
#define BINARY_SEARCH_TREE_COMPARISON_SMALLER_THAN -1
|
||||
/* Return code for comparison, equal. */
|
||||
#define BINARY_SEARCH_TREE_COMPARISON_EQUAL_TO 0
|
||||
/* Return code for comparison, larger. */
|
||||
#define BINARY_SEARCH_TREE_COMPARISON_LARGER_THAN 1
|
||||
|
||||
/* Define all the functions. */
|
||||
/* This function initializes a single node. */
|
||||
tree_node_t* initialize_binary_search_tree_node();
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
/* This file contains the function implementations for binary trees. */
|
||||
#include "binary_tree.h"
|
||||
#define TREE_SUCCESS_CODE 0
|
||||
#define TREE_FAILURE_CODE 1
|
||||
#define TREE_COMPARISON_SMALLER_THAN -1
|
||||
#define TREE_COMPARISON_EQUAL_TO 0
|
||||
#define TREE_COMPARISON_LARGER_THAN 1
|
||||
|
||||
/* This function initializes a new empty tree node, will return NULL on failure. */
|
||||
tree_node_t* initialize_tree_node() {
|
||||
|
|
|
@ -4,6 +4,18 @@
|
|||
#define BINARY_TREE_H
|
||||
#include "../../nodes/tree_node.h"
|
||||
|
||||
/* Define constants. */
|
||||
/* Return code for success. */
|
||||
#define TREE_SUCCESS_CODE 0
|
||||
/* Return code for failure. */
|
||||
#define TREE_FAILURE_CODE 1
|
||||
/* Return code for comparison, smaller. */
|
||||
#define TREE_COMPARISON_SMALLER_THAN -1
|
||||
/* Return code for comparison, equal. */
|
||||
#define TREE_COMPARISON_EQUAL_TO 0
|
||||
/* Return code for comparison, larger. */
|
||||
#define TREE_COMPARISON_LARGER_THAN 1
|
||||
|
||||
/* Define a max macro for use within the depth function. */
|
||||
#define max(a,b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
|
|
Loading…
Reference in New Issue