Compare commits

...

2 commits

Author SHA1 Message Date
Imbus
5b7efc9ef3 Formatting 2024-03-27 06:40:47 +01:00
Imbus
c49f02d8d7 Formatting target using clang-format 2024-03-27 06:39:47 +01:00
4 changed files with 68 additions and 65 deletions

View file

@ -11,6 +11,9 @@ BUILD_DIR := build
# Source files # Source files
SRCS := $(wildcard $(SRC_DIR)/*.c) SRCS := $(wildcard $(SRC_DIR)/*.c)
# Header files (used for formatting)
HEADERS := $(wildcard $(SRC_DIR)/*.h)
# Object files # Object files
OBJS := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SRCS)) OBJS := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SRCS))
@ -33,6 +36,9 @@ $(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
run: $(TARGET) run: $(TARGET)
./$(TARGET) ./$(TARGET)
fmt:
clang-format -i $(SRCS) $(HEADERS)
# Clean rule # Clean rule
clean: clean:
rm -rf $(BUILD_DIR) $(TARGET) rm -rf $(BUILD_DIR) $(TARGET)

View file

@ -24,7 +24,8 @@ int tree_insert(Tree *tree, int data) {
// If larger than data // 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 there is a child to the right
if(cursor->right != NULL) cursor = cursor->right; if (cursor->right != NULL)
cursor = cursor->right;
else { else {
cursor->right = new_node; // Put our node here cursor->right = new_node; // Put our node here
break; // Break the outer while loop break; // Break the outer while loop
@ -34,23 +35,19 @@ int tree_insert(Tree *tree, int data) {
// If less-or-equal than our 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 there is a child to the left
if(cursor->left != NULL) cursor = cursor->left; if (cursor->left != NULL)
cursor = cursor->left;
else { else {
cursor->left = new_node; // Put our node here cursor->left = new_node; // Put our node here
break; // Break the outer while loop break; // Break the outer while loop
} }
} }
} }
} }
int tree_remove(Tree *tree, int data) { int tree_remove(Tree *tree, int data) { return 1; }
return 1;
}
int tree_clear(Tree *tree) { int tree_clear(Tree *tree) { return 1; }
return 1;
}
int tree_size(Tree *tree) { int tree_size(Tree *tree) {
if (tree->root == NULL) { if (tree->root == NULL) {