Compare commits
No commits in common. "5b7efc9ef38a06aeb2aa8c6c8668b32d556f9bac" and "c88d6cefa3860060d9281d1470c51e498cd8486b" have entirely different histories.
5b7efc9ef3
...
c88d6cefa3
4 changed files with 66 additions and 69 deletions
6
Makefile
6
Makefile
|
@ -11,9 +11,6 @@ BUILD_DIR := build
|
|||
# Source files
|
||||
SRCS := $(wildcard $(SRC_DIR)/*.c)
|
||||
|
||||
# Header files (used for formatting)
|
||||
HEADERS := $(wildcard $(SRC_DIR)/*.h)
|
||||
|
||||
# Object files
|
||||
OBJS := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SRCS))
|
||||
|
||||
|
@ -36,9 +33,6 @@ $(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
|
|||
run: $(TARGET)
|
||||
./$(TARGET)
|
||||
|
||||
fmt:
|
||||
clang-format -i $(SRCS) $(HEADERS)
|
||||
|
||||
# Clean rule
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR) $(TARGET)
|
||||
|
|
21
src/tree.c
21
src/tree.c
|
@ -20,12 +20,11 @@ int tree_insert(Tree *tree, int data) {
|
|||
|
||||
// An iterative (non-recursive approach) to tree insertion
|
||||
// While we look for a place to put our new node
|
||||
while (1) {
|
||||
while(1) {
|
||||
// If larger than data
|
||||
if (new_node->data > cursor->data) {
|
||||
if(new_node->data > cursor->data) {
|
||||
// If there is a child to the right
|
||||
if (cursor->right != NULL)
|
||||
cursor = cursor->right;
|
||||
if(cursor->right != NULL) cursor = cursor->right;
|
||||
else {
|
||||
cursor->right = new_node; // Put our node here
|
||||
break; // Break the outer while loop
|
||||
|
@ -33,21 +32,25 @@ int tree_insert(Tree *tree, int data) {
|
|||
}
|
||||
|
||||
// If less-or-equal than our data
|
||||
if (new_node->data <= cursor->data) {
|
||||
if(new_node->data <= cursor->data) {
|
||||
// If there is a child to the left
|
||||
if (cursor->left != NULL)
|
||||
cursor = cursor->left;
|
||||
if(cursor->left != NULL) cursor = cursor->left;
|
||||
else {
|
||||
cursor->left = new_node; // Put our node here
|
||||
break; // Break the outer while loop
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int tree_remove(Tree *tree, int data) { return 1; }
|
||||
int tree_remove(Tree *tree, int data) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int tree_clear(Tree *tree) { return 1; }
|
||||
int tree_clear(Tree *tree) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int tree_size(Tree *tree) {
|
||||
if (tree->root == NULL) {
|
||||
|
|
Loading…
Reference in a new issue