diff --git a/queen_backtrack/Makefile b/queen_backtrack/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..a6af97868d3ebf807a106555c22dead79581ea09 --- /dev/null +++ b/queen_backtrack/Makefile @@ -0,0 +1,36 @@ +CC := gcc +CFLAGS := -Wall -Wextra -g -fsanitize=address -fsanitize=leak + +BIN := bin +SRC := src +INCLUDE := include +LIBRARIES := -lm +EXECUTABLE1 := main + +# ADD ALL THE SOURCES FOR EXECUTABLE1 +SOURCES1 += $(SRC)/$(EXECUTABLE1).c + +.PHONY: all run clean # Specify these are not files but internal terms + +all: $(BIN)/$(EXECUTABLE1) + +run: clean all + clear + @echo "RUNNING..." + ./$(BIN)/$(EXECUTABLE1) + +# # $^ -> dep +# # $@ -> target +# # $< -> premiere dep +# # Compiles directly the c files +# # Not optimal but succint and simple + +# COMPILE FIRST EXECUTABLE +$(BIN)/$(EXECUTABLE1): $(SOURCES1) + @echo "COMPILING..." + $(CC) $(CFLAGS) -I $(INCLUDE) $^ -o $@ $(LIBRARIES) + +clean: + @echo "Cleaning..." + -rm $(BIN)/* + diff --git a/queen_backtrack/bin/main b/queen_backtrack/bin/main new file mode 100755 index 0000000000000000000000000000000000000000..640a186fdfb624aa42f67e03e59094afb3d6a077 Binary files /dev/null and b/queen_backtrack/bin/main differ diff --git a/queen_backtrack/include/queen.h b/queen_backtrack/include/queen.h new file mode 100644 index 0000000000000000000000000000000000000000..fd025c2ce38f7179542ecb2cd009beb75dd6a691 --- /dev/null +++ b/queen_backtrack/include/queen.h @@ -0,0 +1,20 @@ +/* + * HEADER QUEEN + * Author : Jonas S. + * Date : 17/11/2021 + ! QUEEN BACKTRACKING +*/ + + +#include <stdbool.h> +#include <stdint.h> +#include <stdlib.h> + +#ifndef _QUEEN_H_ +#define _QUEEN_H_ + +// DEFINES + +// PROTOTYPE FUNCTIONS + +#endif \ No newline at end of file diff --git a/queen_backtrack/src/main.c b/queen_backtrack/src/main.c new file mode 100644 index 0000000000000000000000000000000000000000..6debd65b76ec3f4744229e676201363560c65b31 --- /dev/null +++ b/queen_backtrack/src/main.c @@ -0,0 +1,14 @@ +/* + * CODE MAIN + * Author : Jonas S. + * Date : 17/11/2021 + ! DESCRIPTION +*/ + +#include <stdio.h> + +int main() +{ + printf("ISSOU\n"); + return 0; +} \ No newline at end of file diff --git a/queen_backtrack/src/queen.c b/queen_backtrack/src/queen.c new file mode 100644 index 0000000000000000000000000000000000000000..e7eecc0238b7ef6132c6f79b1310b5e598b05ed9 --- /dev/null +++ b/queen_backtrack/src/queen.c @@ -0,0 +1,25 @@ +/* + * CODE QUEEN + * Author : Jonas S. + * Date : 17/11/2021 + ! DESCRIPTION +*/ + +#include "../include/queen.h" + +void nbr_solutions(int n, bool board_in[][], int col, int* ptr_cnt) +{ + for (int li = 0; li < n; i++) + { + if (board_in[li][col]) + { + if (col < n - 1) + { + bool board[n][n]; + copy(n, board, board); + prises_devant(n, baord_in[][], board[][], ) + } + } + } + +} diff --git a/stack/include/stack.h b/stack/include/stack.h index 90441572466c049341a9e3c1aae619943469d340..8881b3ab1eec62ba7f1049363437cfdd094a5552 100644 --- a/stack/include/stack.h +++ b/stack/include/stack.h @@ -14,22 +14,30 @@ #define _STACK_H_ // DEFINES -#define INCREMENT_STACK 100 +#define INCREMENT_STACK 5 + +// TERMINAL COLOR DEFINES +#define TERM_GREEN "\x1B[32m" +#define TERM_RED "\x1B[31m" +#define TERM_WHITE "\x1B[37m" + typedef struct -{ - uint64_t max; +{ + int64_t max; int64_t top; int32_t *data; }stack_t; // PROTOTYPE FUNCTIONS -int32_t* create_stack(uint64_t capa); +stack_t* create_stack(uint64_t capa); void stack_push(stack_t* st, int32_t val); -int32_t stack_pop(stack_t* st); -int32_t stack_peek(stack_t st); +void stack_pop(stack_t* st, int32_t* val); +void stack_peek(stack_t st, int32_t* val); bool stack_is_full(stack_t st); bool stack_is_empty(stack_t st); void stack_destroy(stack_t* st); +void stack_show(stack_t st); + #endif \ No newline at end of file diff --git a/stack/src/stack.c b/stack/src/stack.c index 069ca2a7e5d3cc33dceddff88ff11e4fa975d0b2..adc6d3514f30cfad77a49a52602a352b97c728d2 100644 --- a/stack/src/stack.c +++ b/stack/src/stack.c @@ -7,47 +7,129 @@ #include "../include/stack.h" -int32_t* create_stack(uint64_t capa) +/** + * @brief Return pointer to stack with given size + * + * @param capa + * @return stack_t* + */ +stack_t* create_stack(uint64_t capa) { stack_t* st = malloc(sizeof(stack_t)); st->max = capa; st->data = malloc(st->max * sizeof(int32_t)); st->top = -1; + return st; } -void stack_push(stack_t* st, int32_t val) +/** + * @brief Free a stack + * + * @param st + */ +void stack_destroy(stack_t* st) { - // UP CAPACITY WHEN MAX IS REACHED - if(st->top == st->max) - { - realloc(st->data, st->max + INCREMENT_STACK); - } - st->data[++st->top] = val; + free(st->data); + free(st); } -int32_t stack_pop(stack_t* st) +/** + * @brief Check is a stack is empty + * + * @param st + * @return true + * @return false + */ +bool stack_is_empty(stack_t st) { - return st->data[st->top--]; + return st.top == -1; } -int32_t stack_peek(stack_t st) +/** + * @brief Check if a stack is full + * + * @param st + * @return true + * @return false + */ +bool stack_is_full(stack_t st) { - return st.data[st.top]; + return st.top == st.max - 1; } -bool stack_is_full(stack_t st) +/** + * @brief Push an given element to a stack + * + * @param st + * @param val + */ +void stack_push(stack_t* st, int32_t val) { - return st.top == st.max; + // UP CAPACITY WHEN MAX IS REACHED + if(stack_is_full(*st)) + { + st->max += INCREMENT_STACK; + st->data = realloc(st->data, st->max * sizeof(int32_t)); + fprintf(stderr, "%sPUSH: MAX CAPAXITY INCREMENTED%s\n", TERM_RED, TERM_WHITE); + } + st->data[++st->top] = val; } -bool stack_is_empty(stack_t st) +/** + * @brief Pop the last element on the stack + * + * @param st + * @param val + */ +void stack_pop(stack_t* st, int32_t* val) { - return st.top == -1; + if( stack_is_empty(*st) ) + { + fprintf(stderr, "%sCANNOT POP: STACK IS EMPTY%s\n", TERM_RED, TERM_WHITE); + return; + } + *val = st->data[st->top--]; } - -void stack_destroy(stack_t* st) +/** + * @brief Get the last element on the stack + * + * @param st + * @param val + */ +void stack_peek(stack_t st, int32_t* val) { - free(st->data); - free(st); + if( stack_is_empty(st) ) + { + fprintf(stderr, "%sCANNOT PEEK: STACK IS EMPTY%s\n", TERM_RED, TERM_WHITE); + return; + } + *val = st.data[st.top]; } + +/** + * @brief Show a stack + * + * @param st + */ +void stack_show(stack_t st) +{ + if( stack_is_empty(st) ) + { + fprintf(stderr, "%sCANNOT SHOW: STACK IS EMPTY%s\n", TERM_RED, TERM_WHITE); + return; + } + printf("%s", TERM_GREEN); + printf("------------------------------\n"); + printf("----------- STACK -----------\n"); + printf("------------------------------\n"); + + printf("MAX SIZE : %ld\n", st.max); + printf("TOP INDEX : %ld\n", st.top); + + for (int32_t i = 0; i < st.top + 1; i++) + { + printf("%d - %d\n", i, st.data[i]); + } + printf("%s\n", TERM_WHITE); +} \ No newline at end of file