This commit is contained in:
Etienne Rey-bethbeder 2022-12-04 19:48:24 +01:00
parent 89c4b4ee44
commit 665552486a
6 changed files with 90 additions and 30 deletions

BIN
.push_swap.c.swn Normal file

Binary file not shown.

View file

@ -6,16 +6,17 @@
# By: erey-bet <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# 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

BIN
push_swap Executable file

Binary file not shown.

View file

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdio.h>
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++;
min = get_min(tab, len);
tab[min] = 2147483648;
new[min] = i;
}
old_min = min;
}
}
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);

View file

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <unistd.h>
# include <stdlib.h>
typedef struct s_stack
{
unsigned int *list;
int len;
} t_stack;
#endif

BIN
push_swap.o Normal file

Binary file not shown.