setting up my preset but i need to valgrind

This commit is contained in:
Maoake
2025-12-22 20:37:12 +00:00
parent e563d663ec
commit 96a0a6d8f0
9 changed files with 168 additions and 24 deletions

View File

@@ -6,7 +6,7 @@ ALGO_DIR = algorithms
MEDIUM_DIR = medium_utils
SRC = main.c ft_atoi.c parsing.c
SRC = main.c ft_atoi.c parsing.c parsing_2.c test_one.c
STACK_UTILS = push.c rev_rotate.c rotate.c stack_add.c stack_remove.c swap.c

View File

@@ -12,12 +12,12 @@
#include "push_swap.h"
void bucket_algo(t_stacks *piles)
void bucket_algo(void)
{
int range;
/*int range;
t_tab *preset;
range = range_bucket(piles->a);
preset = get_tabs(piles->a, range);
preset = get_tabs(piles->a, range);*/
return ;
}

View File

@@ -21,7 +21,7 @@ int get_first_lower(t_stack *first)
lower = tmp->value;
while (tmp->next != first)
{
if (lower < tmp->value)
if (lower > tmp->value)
lower = tmp->value;
tmp = tmp->next;
}
@@ -34,11 +34,14 @@ int get_next_lower(t_stack *first, int old_lower)
int next_lower;
tmp = first;
next_lower = tmp->value;
next_lower = 2147483646;
while (tmp->next != first)
{
if (tmp->value != old_lower && next_lower < tmp->value)
if (old_lower < tmp->value && tmp->value <= next_lower)
{
next_lower = tmp->value;
}
tmp = tmp->next;
}
return (next_lower);
@@ -85,5 +88,7 @@ int get_number_in_range(int max_range, t_stack *a, int range)
nb_in++;
tmp = tmp->next;
}
if (in_range(tmp->value, max_range, range))
nb_in++;
return (nb_in);
}

View File

@@ -25,6 +25,8 @@ t_tab *allocate_tab(int range_max, int nb)
return (tab);
}
#include <stdio.h>
t_tab *get_tabs(t_stack *first, int range)
{
t_tab *tmp;

24
main.c
View File

@@ -13,6 +13,7 @@
#include "push_swap.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void print_all_stack(t_stack *stack, t_stack *first, char pile)
{
@@ -54,7 +55,7 @@ int adding_number(int *tab, int len)
stock = tab[0];
while (!verif_no_double(tab, len, stock))
{
stock = rand();
stock = 0 + rand() % (250 - 0 + 1);
}
return stock;
}
@@ -63,13 +64,12 @@ int *auto_shuffle(int len_tab)
{
int *tab;
int i;
int len_added;
i = 1;
tab = malloc(len_tab * sizeof(int));
if (!tab)
return (NULL);
tab[0] = rand();
tab[0] = 0 + rand() % (250 - 0 + 1);
while (i < len_tab)
{
tab[i] = adding_number(tab, i);
@@ -81,20 +81,12 @@ int *auto_shuffle(int len_tab)
int main(int argc, char **argv)
{
t_stacks *stacks;
stacks = NULL;
if (argc > 1)
{
stacks = init_big_stacks(argc, argv);
print_all_stack(stacks->a, stacks->a, 'A');
print_all_stack(stacks->b, stacks->b, 'B');
rra(stacks);
print_all_stack(stacks->a, stacks->a, 'A');
print_all_stack(stacks->b, stacks->b, 'B');
if (strcmp(argv[1], "-t1") == 0)
test1(argc, argv++);
else if (strcmp(argv[1], "-t2") == 0)
test2(argv++);
}
if (stacks->a)
stack_clear_all(stacks->a, stacks->a);
if (stacks->b)
stack_clear_all(stacks->b, stacks->b);
return (0);
}

67
parsing_2.c Normal file
View File

@@ -0,0 +1,67 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parsing_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mteriier <mteriier@student.lyon42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/22 13:10:58 by mteriier #+# #+# */
/* Updated: 2025/12/22 13:11:21 by mteriier ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
#include <stdlib.h>
#include <stdio.h>
void print_tabs(t_tab *preset)
{
t_tab *tab;
tab = preset;
while (tab)
{
printf("MAX RANGE : [%d]\n", tab->max_range);
printf("NUMBER IN : [%d]\n", tab->nb_in);
tab = tab->next;
}
}
t_stack *parsing2(int *tab, int len)
{
int i;
int stock;
t_stack *first;
t_stack *new;
i = 0;
first = NULL;
while (i < len)
{
stock = tab[i];
new = new_stack(stock);
if (!new && !first)
return (NULL);
else if (!new)
{
stack_clear_all(first, first);
return (NULL);
}
stack_add_back(&first, new);
i++;
}
return (first);
}
t_stacks *init_big_stacks2(int *tab, int len)
{
t_stacks *stacks;
t_stack *a;
stacks = malloc(sizeof(t_stacks));
if (!stacks)
return (NULL);
a = parsing2(tab, len);
stacks->a = a;
return (stacks);
}

BIN
push_swap Executable file

Binary file not shown.

View File

@@ -72,5 +72,17 @@ t_tab *free_tab(t_tab *first);
t_tab *get_next_tab(t_stack *first, t_tab *tab, int range);
t_tab *init_first_tab(t_stack *first, int range);
t_tab *allocate_tab(int range_max, int nb);
/*FUNCTION IN MAIN*/
void print_all_stack(t_stack *stack, t_stack *first, char pile);
int verif_no_double(int *tab, int len, int value);
int adding_number(int *tab, int len);
int *auto_shuffle(int len_tab);
/*FUNCTION IN FILE TEST*/
int test1(int argc, char **argv);
int test2(char **argv);
/*FUNCTION IN PARSIN 2*/
t_stack *parsing2(int *tab, int len);
t_stacks *init_big_stacks2(int *tab, int len);
void print_tabs(t_tab *preset);
#endif

66
test_one.c Normal file
View File

@@ -0,0 +1,66 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test_one.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mteriier <mteriier@student.lyon42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/22 12:33:58 by mteriier #+# #+# */
/* Updated: 2025/12/22 12:34:35 by mteriier ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
#include <stdio.h>
#include <stdlib.h>
int test1(int argc, char **argv)
{
t_stacks *stacks;
stacks = NULL;
if (argc > 1)
{
stacks = init_big_stacks(argc, argv);
print_all_stack(stacks->a, stacks->a, 'A');
print_all_stack(stacks->b, stacks->b, 'B');
rra(stacks);
print_all_stack(stacks->a, stacks->a, 'A');
print_all_stack(stacks->b, stacks->b, 'B');
}
if (stacks->a)
stack_clear_all(stacks->a, stacks->a);
if (stacks->b)
stack_clear_all(stacks->b, stacks->b);
return (0);
}
int test2(char **argv){
int *tab;
int len;
t_tab *preset;
t_stacks *piles;
int i;
i = 0;
len = ft_atoi(argv[2]);
if (len < 1)
{
printf("WRONG LEN PLS BE SMART.\n");
return (0);
}
tab = auto_shuffle(len);
while (i < len)
{
printf("tab(%d) [%d]\n", i, tab[i]);
i++;
}
piles = init_big_stacks2(tab, len);
printf("RANGE BUCKET %d\n", range_bucket(piles->a));
preset = get_tabs(piles->a, range_bucket(piles->a));
print_tabs(preset);
free(tab);
free_tab(preset);
return (0);
}