diff --git a/.push_swap.c.swn b/.push_swap.c.swn new file mode 100644 index 0000000..37ca323 Binary files /dev/null and b/.push_swap.c.swn differ diff --git a/Makefile b/Makefile index c8358b5..ecf0fda 100644 --- a/Makefile +++ b/Makefile @@ -6,16 +6,17 @@ # By: erey-bet +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2022/09/27 04:19:30 by erey-bet #+# #+# # -# Updated: 2022/11/23 16:46:50 by erey-bet ### ########.fr # +# Updated: 2022/12/02 19:24:34 by erey-bet ### ########.fr # # # # **************************************************************************** # SRCS = push_swap.c OBJS = ${SRCS:.c=.o} CC = clang -CFLAGS = -Wall -Wextra -Werror +CFLAGS = -g -Wall -Wextra -Werror NAME = push_swap +# TU OUBLIS PAS LE -G DANS CFLAGS HEIN all: ${NAME} @@ -136,4 +137,4 @@ coffee: @echo ' """------"""' ${MAKE} coffee -.PHONY: all clean fclean re coffee +.PHONY: all clean fclean re coffee gdb diff --git a/push_swap b/push_swap new file mode 100755 index 0000000..0b9d24f Binary files /dev/null and b/push_swap differ diff --git a/push_swap.c b/push_swap.c index 1bf7741..c1caf43 100644 --- a/push_swap.c +++ b/push_swap.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/11/23 16:48:12 by erey-bet #+# #+# */ -/* Updated: 2022/11/30 20:05:21 by erey-bet ### ########.fr */ +/* Updated: 2022/12/04 19:48:15 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,51 +15,105 @@ #include -void get_index(int **tab,int len) +int get_min(long *tab, int len) +{ + int i; + int index; + + i = 0; + index = 0; + while (++i < len) + if (tab[i] <= tab[index]) + index = i; + return (index); +} + +unsigned int *get_index(long *tab, int len) { int i; - int y; int min; - int old_min; - int new_index; + unsigned int *new; i = -1; - min = *tab[0]; - old_min = *tab[0]; - new_index = 0; + min = tab[0]; + new = malloc(sizeof(unsigned int) * (len + 1)); while (++i < len) { - y = -1; - while (++y < len) - { - if (*tab[y] < min && *tab[y] <= old_min) - { - min = *tab[y]; - *tab[y] = new_index++; - } - old_min = min; - } + min = get_min(tab, len); + tab[min] = 2147483648; + new[min] = i; } - for (i = 0 ; i < len ; i++) + return (new); +} + +void swap(t_stack *s) +{ + unsigned int c; + + c = *s.list[0]; + *s.list[0] = *s.list[1]; + *s.list[1] = c; + write(1, "sa", 2); +} + +void push(t_stack *s_push, t_stack *s_receive, char *message) +{ + int i; + int push; + + i = 0; + push = *s_push.list[0]; + while (++i < *s_push.len) + *s_push.list[i - 1] = *s_push.list[i]; + i = 0; + while (++i < *s_receive.len) { - printf("%d", *tab[i]); + } } -void push_swap(int *tab, int len) +void rotate() { - get_index(&tab, len); + +} + +void get_number_in_top(t_stack **s, int y, int len) +{ + if (len - y + 1 < len / 2) +} + +void push_swap(long *tab, int len) +{ + int i; + int y; + t_stack sa; + t_stack sb; + + sa.list = get_index(tab, len); + sa.len = len; + sb.list = malloc(sizeof(unsigned int) * (len + 1)); + sb.len = 0; + i = 0; + y = 1; + while (i < len) + { + if ((sa.list[i] >> y) & 1 == 1) + { + if (i > 0) + // get number in top + } + } } int main(int argc, char *argv[]) { - int *tab; + long *tab; int i; int y; i = 0; y = 0; - tab = malloc(sizeof(int) * (argc + 1)); + tab = malloc(sizeof(long) * (argc + 1)); if (argc > 1) { while (++i < argc) @@ -72,8 +126,7 @@ int main(int argc, char *argv[]) return (1); } } - get_index(&tab, y); - //push_swap(tab, argc); + get_index(tab, y); } return (0); diff --git a/push_swap.h b/push_swap.h index 8d982c2..b21b619 100644 --- a/push_swap.h +++ b/push_swap.h @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/11/23 16:51:31 by erey-bet #+# #+# */ -/* Updated: 2022/11/23 16:53:17 by erey-bet ### ########.fr */ +/* Updated: 2022/12/04 18:02:57 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,4 +16,10 @@ # include # include +typedef struct s_stack +{ + unsigned int *list; + int len; +} t_stack; + #endif diff --git a/push_swap.o b/push_swap.o new file mode 100644 index 0000000..ff1edb8 Binary files /dev/null and b/push_swap.o differ