commit a97f290271e8467bfc6640ad1ffa0b53af77820f Author: Lucas Date: Mon Apr 20 20:09:16 2026 +0200 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2b29547 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.gz +*.html diff --git a/README b/README new file mode 100644 index 0000000..e69de29 diff --git a/The-Nook-GamesTM/Fundamentals/basic_tree.c b/The-Nook-GamesTM/Fundamentals/basic_tree.c new file mode 100644 index 0000000..5f2c595 --- /dev/null +++ b/The-Nook-GamesTM/Fundamentals/basic_tree.c @@ -0,0 +1,9 @@ +#include "basic_tree.h" + +struct node *insert(struct node *root, int value); + +void delete_leaf(struct node *root, int value); + +struct node *delete_node(struct node *root, int value); + +void pretty_print(struct node *root); \ No newline at end of file diff --git a/The-Nook-GamesTM/Fundamentals/basic_tree.h b/The-Nook-GamesTM/Fundamentals/basic_tree.h new file mode 100644 index 0000000..dfbe889 --- /dev/null +++ b/The-Nook-GamesTM/Fundamentals/basic_tree.h @@ -0,0 +1,25 @@ +#ifndef BASIC_TREE_H +#define BASIC_TREE_H + +struct queue { + struct node *node; + struct queue *next; +}; + +struct queue *enqueue(struct queue *queue, struct node *node); +struct node *dequeue(struct queue **queue); +void queue_destroy(struct queue *queue); + + +struct node { + int value; + struct node *left; + struct node *right; +}; + +struct node *insert(struct node *root, int value); +void delete_leaf(struct node *root, int value); +struct node *delete_node(struct node *root, int value); +void pretty_print(struct node *root); + +#endif /* ! BASIC_TREE_H */ \ No newline at end of file diff --git a/The-Nook-GamesTM/Fundamentals/basic_tree_aux.c b/The-Nook-GamesTM/Fundamentals/basic_tree_aux.c new file mode 100644 index 0000000..dbd9694 --- /dev/null +++ b/The-Nook-GamesTM/Fundamentals/basic_tree_aux.c @@ -0,0 +1,35 @@ +#include "basic_tree.h" +#include + +struct queue *enqueue(struct queue *queue, struct node *node) { + struct queue *new_elt = malloc(sizeof(struct queue)); + if (!new_elt) + return queue; + new_elt->node = node; + new_elt->next = NULL; + if (!queue) { + return new_elt; + } + struct queue *it = queue; + while (it->next) { + it = it->next; + } + it->next = new_elt; + return queue; +} + +struct node *dequeue(struct queue **queue) { + if (!queue || !*queue) + return NULL; + struct node *res = (*queue)->node; + struct queue *temp = *queue; + *queue = (*queue)->next; + free(temp); + return res; +} + +void queue_destroy(struct queue *queue) { + while (queue) { + dequeue(&queue); + } +} \ No newline at end of file diff --git a/The-Nook-GamesTM/Fundamentals/expansion.c b/The-Nook-GamesTM/Fundamentals/expansion.c new file mode 100644 index 0000000..5931a94 --- /dev/null +++ b/The-Nook-GamesTM/Fundamentals/expansion.c @@ -0,0 +1,3 @@ +#include "expansion.h" + +char *weird_copy(const char *input); \ No newline at end of file diff --git a/The-Nook-GamesTM/Fundamentals/expansion.h b/The-Nook-GamesTM/Fundamentals/expansion.h new file mode 100644 index 0000000..47428fd --- /dev/null +++ b/The-Nook-GamesTM/Fundamentals/expansion.h @@ -0,0 +1,20 @@ +#ifndef EXPANSION_H +#define EXPANSION_H + +#include + +struct var { + char *key; + char *value; + struct var *next; +}; + +struct var *var_add(struct var *list, const char *key, const char *value); +const char *var_get(struct var *list, const char *key); +size_t var_size(struct var *list); +int var_update(struct var *list, const char *key, const char *value); +void var_free(struct var *list); + +char *weird_copy(const char *input); + +#endif /* ! EXPANSION_H */ \ No newline at end of file diff --git a/The-Nook-GamesTM/Fundamentals/expansion_aux.c b/The-Nook-GamesTM/Fundamentals/expansion_aux.c new file mode 100644 index 0000000..7d6952b --- /dev/null +++ b/The-Nook-GamesTM/Fundamentals/expansion_aux.c @@ -0,0 +1,66 @@ +#include "expansion.h" + +#include +#include + +struct var *var_add(struct var *list, const char *key, const char *value) { + struct var *node = malloc(sizeof(struct var)); + if (!node) + return NULL; + node->key = strdup(key); + node->value = strdup(value); + if (!node->key || !node->value) { + free(node->key); + free(node->value); + free(node); + return NULL; + } + node->next = list; + return node; +} + +const char *var_get(struct var *list, const char *key) { + while (list) + { + if (strcmp(list->key, key) == 0) + return list->value; + list = list->next; + } + return NULL; +} + +size_t var_size(struct var *list) { + size_t n = 0; + while (list) + { + n++; + list = list->next; + } + return n; +} + +int var_update(struct var *list, const char *key, const char *value) { + while (list) + { + if (strcmp(list->key, key) == 0) { + char *new_val = strdup(value); + if (!new_val) + return -1; + free(list->value); + list->value = new_val; + return 0; + } + list = list->next; + } + return -1; +} + +void var_free(struct var *list) { + while (list) { + struct var *next = list->next; + free(list->key); + free(list->value); + free(list); + list = next; + } +} diff --git a/The-Nook-GamesTM/Fundamentals/parsing.c b/The-Nook-GamesTM/Fundamentals/parsing.c new file mode 100644 index 0000000..f4ef08b --- /dev/null +++ b/The-Nook-GamesTM/Fundamentals/parsing.c @@ -0,0 +1,13 @@ +#include "parsing.h" +#include +#include +#include +#include + +struct node *create_node(const char *line); + +struct node *parse_file(const char *filename); + +void execute_tree(struct node *node, int value); + +int main(int argc, char *argv[]); \ No newline at end of file diff --git a/The-Nook-GamesTM/Fundamentals/parsing.h b/The-Nook-GamesTM/Fundamentals/parsing.h new file mode 100644 index 0000000..802ea7c --- /dev/null +++ b/The-Nook-GamesTM/Fundamentals/parsing.h @@ -0,0 +1,49 @@ +#ifndef PARSING_H +#define PARSING_H + +#include + +enum node_type { + EMPTY, + PLUS, + MINUS, + PRINT +}; + +enum child { + LEFT, + RIGHT +}; + +enum condition_type { + INT, + CHILD +}; + +union condition { + int n; + enum child child; +}; + +struct node { + enum node_type node_type; + union condition condition; + enum condition_type condition_type; + struct node *left; + struct node *right; +}; + +struct queue { + struct node *node; + struct queue *next; +}; + +struct queue *enqueue(struct queue *queue, struct node *node); +struct node *dequeue(struct queue **queue); +void queue_destroy(struct queue *queue); + +struct node *create_node(const char *line); +struct node *parse_file(const char *filename); +void execute_tree(struct node *node, int value); + +#endif /* ! PARSING_H */ \ No newline at end of file diff --git a/The-Nook-GamesTM/Fundamentals/parsing_aux.c b/The-Nook-GamesTM/Fundamentals/parsing_aux.c new file mode 100644 index 0000000..238772c --- /dev/null +++ b/The-Nook-GamesTM/Fundamentals/parsing_aux.c @@ -0,0 +1,35 @@ +#include "parsing.h" +#include + +struct queue *enqueue(struct queue *queue, struct node *node) { + struct queue *new_elt = malloc(sizeof(struct queue)); + if (!new_elt) + return queue; + new_elt->node = node; + new_elt->next = NULL; + if (!queue) { + return new_elt; + } + struct queue *it = queue; + while (it->next) { + it = it->next; + } + it->next = new_elt; + return queue; +} + +struct node *dequeue(struct queue **queue) { + if (!queue || !*queue) + return NULL; + struct node *res = (*queue)->node; + struct queue *temp = *queue; + *queue = (*queue)->next; + free(temp); + return res; +} + +void queue_destroy(struct queue *queue) { + while (queue) { + dequeue(&queue); + } +} \ No newline at end of file diff --git a/The-Nook-GamesTM/Fundamentals/vector_tree.c b/The-Nook-GamesTM/Fundamentals/vector_tree.c new file mode 100644 index 0000000..5e5ac7e --- /dev/null +++ b/The-Nook-GamesTM/Fundamentals/vector_tree.c @@ -0,0 +1,7 @@ +#include "vector_tree.h" + +struct vector *insert(struct vector *tree, int value); + +void delete_node(struct vector *tree, int value); + +void pretty_print(struct vector *tree); \ No newline at end of file diff --git a/The-Nook-GamesTM/Fundamentals/vector_tree.h b/The-Nook-GamesTM/Fundamentals/vector_tree.h new file mode 100644 index 0000000..4de8f76 --- /dev/null +++ b/The-Nook-GamesTM/Fundamentals/vector_tree.h @@ -0,0 +1,16 @@ +#ifndef VECTOR_TREE +#define VECTOR_TREE + +#include + +struct vector { + int *values; + size_t size; + size_t nb_elements; +}; + +struct vector *insert(struct vector *tree, int value); +void delete_node(struct vector *tree, int value); +void pretty_print(struct vector *tree); + +#endif /* ! VECTOR_TREE */ \ No newline at end of file diff --git a/The-Nook-GamesTM/Proficiencies/evaluate_rpn.c b/The-Nook-GamesTM/Proficiencies/evaluate_rpn.c new file mode 100644 index 0000000..97cec10 --- /dev/null +++ b/The-Nook-GamesTM/Proficiencies/evaluate_rpn.c @@ -0,0 +1,3 @@ +#include "evaluate_rpn.h" + +int evaluate_rpn(struct queue *queue); \ No newline at end of file diff --git a/The-Nook-GamesTM/Proficiencies/evaluate_rpn.h b/The-Nook-GamesTM/Proficiencies/evaluate_rpn.h new file mode 100644 index 0000000..34a9cd6 --- /dev/null +++ b/The-Nook-GamesTM/Proficiencies/evaluate_rpn.h @@ -0,0 +1,8 @@ +#ifndef EVALUATE_RPN_H +#define EVALUATE_RPN_H + +#include "queue.h" + +int evaluate_rpn(struct queue *queue); + +#endif /* ! EVALUATE_RPN_H*/ \ No newline at end of file diff --git a/The-Nook-GamesTM/Proficiencies/main.c b/The-Nook-GamesTM/Proficiencies/main.c new file mode 100644 index 0000000..d746ac7 --- /dev/null +++ b/The-Nook-GamesTM/Proficiencies/main.c @@ -0,0 +1 @@ +int main(int argc, char** argv); \ No newline at end of file diff --git a/The-Nook-GamesTM/Proficiencies/parse_exp.c b/The-Nook-GamesTM/Proficiencies/parse_exp.c new file mode 100644 index 0000000..7e005ee --- /dev/null +++ b/The-Nook-GamesTM/Proficiencies/parse_exp.c @@ -0,0 +1,3 @@ +#include "parse_exp.h" + +struct queue *parse_expression(const char *str); \ No newline at end of file diff --git a/The-Nook-GamesTM/Proficiencies/parse_exp.h b/The-Nook-GamesTM/Proficiencies/parse_exp.h new file mode 100644 index 0000000..95ec5a9 --- /dev/null +++ b/The-Nook-GamesTM/Proficiencies/parse_exp.h @@ -0,0 +1,8 @@ +#ifndef PARSE_EXP_H +#define PARSE_EXP_H + +#include "queue.h" + +struct queue *parse_expression(const char *str); + +#endif /* ! PARSE_EXP_H */ \ No newline at end of file diff --git a/The-Nook-GamesTM/Proficiencies/queue.c b/The-Nook-GamesTM/Proficiencies/queue.c new file mode 100644 index 0000000..49ab79f --- /dev/null +++ b/The-Nook-GamesTM/Proficiencies/queue.c @@ -0,0 +1,41 @@ +#include "queue.h" + +struct queue *enqueue(struct queue *queue, struct expression_element* element) { + struct queue *new_elt = calloc(1,sizeof(struct queue)); + + new_elt->data = element; + + if(!queue) + return new_elt; + + struct queue* current = queue; + + while(current->next) + current = current->next; + + current->next = new_elt; + + return queue; +} + +struct expression_element* dequeue(struct queue **queue) { + if (!queue || !*queue) + return NULL; + + struct queue* removed = *queue; + struct expression_element* res = removed->data; + + *queue = removed->next; + free(removed); + + return res; +} + +void queue_destroy(struct queue **queue) { + if(!queue) + return; + while (*queue) { + struct expression_element* dequeued = dequeue(queue); + free(dequeued); + } +} \ No newline at end of file diff --git a/The-Nook-GamesTM/Proficiencies/queue.h b/The-Nook-GamesTM/Proficiencies/queue.h new file mode 100644 index 0000000..96c7512 --- /dev/null +++ b/The-Nook-GamesTM/Proficiencies/queue.h @@ -0,0 +1,31 @@ +#ifndef QUEUE_H +#define QUEUE_H + +#include + +union element_type +{ + int operand; + char operator; +}; + +enum element_tag { + TOKEN_OPERAND, + TOKEN_OPERATOR +}; + +struct expression_element { + enum element_tag tag; + union element_type data; +}; + +struct queue { + struct expression_element* data; + struct queue *next; +}; + +struct queue *enqueue(struct queue *queue, struct expression_element* element); +struct expression_element* dequeue(struct queue **queue); +void queue_destroy(struct queue **queue); + +#endif /* ! QUEUE_H */ \ No newline at end of file diff --git a/The-Nook-GamesTM/Proficiencies/stack.c b/The-Nook-GamesTM/Proficiencies/stack.c new file mode 100644 index 0000000..71b583c --- /dev/null +++ b/The-Nook-GamesTM/Proficiencies/stack.c @@ -0,0 +1,36 @@ +#include "stack.h" + +struct stack *stack_push(struct stack *s, struct expression_element e) +{ + struct stack *new = malloc(sizeof(struct stack)); + new->next = NULL; + new->data = e; + if (s == NULL) + return new; + new->next = s; + return new; +} + +struct stack *stack_pop(struct stack *s) +{ + if (!s) + return NULL; + struct stack *next = s->next; + free(s); + return next; +} + +void stack_destroy(struct stack **s) +{ + if(!s) + return; + while (*s) + { + *s = stack_pop(*s); + } +} + +struct expression_element stack_peek(struct stack *s) +{ + return s->data; +} \ No newline at end of file diff --git a/The-Nook-GamesTM/Proficiencies/stack.h b/The-Nook-GamesTM/Proficiencies/stack.h new file mode 100644 index 0000000..4dca8cf --- /dev/null +++ b/The-Nook-GamesTM/Proficiencies/stack.h @@ -0,0 +1,40 @@ +#ifndef STACK_H +#define STACK_H + +#include + +union element_type +{ + int operand; + char operator; +}; + +enum element_tag { + TOKEN_OPERAND, + TOKEN_OPERATOR +}; + +struct expression_element { + enum element_tag tag; + union element_type data; +}; + +struct stack { + struct expression_element data; + struct stack *next; +}; + +/* Push a new element to the stack and returns the new top */ +struct stack *stack_push(struct stack *s, struct expression_element element); + +/* Pop from the stack and returns its new top */ +struct stack *stack_pop(struct stack *s); + +/* Empty and frees the whole stack */ +void stack_destroy(struct stack **s); + +/* Returns the current top of the stack */ +struct expression_element stack_peek(struct stack *s); + + +#endif /* ! STACK_H */ \ No newline at end of file