Skip to content
Snippets Groups Projects

Final commit

1 file
+ 6
5
Compare changes
  • Side-by-side
  • Inline
+ 32
11
@@ -5,15 +5,20 @@
#include <stdlib.h>
#include <string.h>
typedef struct Node {
typedef struct Node
{
/**
* Parent of this node
*/
struct Node *parent;
/**
* Left child of this node
*/
struct Node* left;
struct Node *left;
/**
* Right child of this node
*/
struct Node* right;
struct Node *right;
/**
* The age of the data in this node
*/
@@ -21,10 +26,11 @@ typedef struct Node {
/**
* The name of the data in this node
*/
char* name;
char *name;
} Node;
typedef struct Tree {
typedef struct Tree
{
Node *root;
} Tree;
@@ -36,7 +42,7 @@ typedef struct Tree {
* @param name The name value for the first data point
* @return The root Node of the tree
*/
Tree* tree_create();
Tree *tree_create();
/**
* Delete an entire tree. This will delete the passed Node and all children below it
@@ -44,7 +50,7 @@ Tree* tree_create();
* DO NOT MODIFY THE METHOD SIGNATURE
* @param node The root Node of the tree to delete.
*/
void tree_delete(Tree* tree);
void tree_delete(Tree *tree);
/**
* Insert a new data point into the tree
@@ -54,7 +60,7 @@ void tree_delete(Tree* tree);
* @param age The age part of the data point
* @param name The name part of the data point
*/
void tree_insert(Tree* tree, int age, char* name);
void tree_insert(Tree *tree, int age, char *name);
/**
* Remove a data point from a tree
@@ -64,7 +70,7 @@ void tree_insert(Tree* tree, int age, char* name);
* @param age The age part of the data point to delete
* @param name The name part of the data point to delete
*/
void tree_erase(Tree* tree, int age, char* name);
void tree_erase(Tree *tree, int age, char *name);
/**
* Print a tree in the following format:
@@ -79,6 +85,12 @@ void tree_erase(Tree* tree, int age, char* name);
*/
void tree_print(Tree *tree, int printNewline);
/**
* Print the tree in a fancy way for debugging.
* Also prints whether the parent-child relation is correct.
*/
void tree_fancy_print(Tree *tree, int printNewline);
/**
* Find an item in the tree. Should return the tree node containing the data specified if found, or NULL if not
*
@@ -88,6 +100,15 @@ void tree_print(Tree *tree, int printNewline);
* @param name The name to look for
* @return
*/
Node* tree_find(Tree* node, int age, char* name);
Node *tree_find(Tree *node, int age, char *name);
// Assumes from is not null!!
Node *find_replacement_node(Node *from);
// Assumes from is not null!!
Node *find_rightmost_node(Node *from);
void cut_node_free(Node *node);
char *checkChildrenRelationship(Node *parentNode);
#endif //C_IMPLEMENTATION_TREE_H
#endif // C_IMPLEMENTATION_TREE_H
Loading