add free on day 5
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */
|
/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/12/05 08:50:09 by tomoron ### ########.fr */
|
/* Updated: 2024/12/15 19:20:04 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -74,7 +74,6 @@ static int respect_order(int *nbrs, t_orders *orders, int len)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
// int tmp;
|
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while(i < len)
|
while(i < len)
|
||||||
@ -85,12 +84,7 @@ static int respect_order(int *nbrs, t_orders *orders, int len)
|
|||||||
if(i != j)
|
if(i != j)
|
||||||
{
|
{
|
||||||
if(nbrs[i] == orders->left && nbrs[j] == orders->right && i > j)
|
if(nbrs[i] == orders->left && nbrs[j] == orders->right && i > j)
|
||||||
{
|
|
||||||
// tmp = nbrs[i];
|
|
||||||
// nbrs[i] = nbrs[j];
|
|
||||||
// nbrs[j] = tmp;
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
@ -119,7 +113,10 @@ static long int check_line(char *line, t_orders *orders)
|
|||||||
|
|
||||||
nbrs = get_numbers(line, &len);
|
nbrs = get_numbers(line, &len);
|
||||||
if(!is_ordered(nbrs, orders, len))
|
if(!is_ordered(nbrs, orders, len))
|
||||||
|
{
|
||||||
|
free(nbrs);
|
||||||
return(0);
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
res = nbrs[(len / 2)];
|
res = nbrs[(len / 2)];
|
||||||
free(nbrs);
|
free(nbrs);
|
||||||
@ -130,6 +127,7 @@ long int resolve_part1(char *input, char **split)
|
|||||||
{
|
{
|
||||||
(void)input;
|
(void)input;
|
||||||
t_orders *orders;
|
t_orders *orders;
|
||||||
|
t_orders *tmp;
|
||||||
long int res;
|
long int res;
|
||||||
|
|
||||||
orders = 0;
|
orders = 0;
|
||||||
@ -144,5 +142,11 @@ long int resolve_part1(char *input, char **split)
|
|||||||
res += check_line(*split, orders);
|
res += check_line(*split, orders);
|
||||||
split++;
|
split++;
|
||||||
}
|
}
|
||||||
|
while(orders)
|
||||||
|
{
|
||||||
|
tmp = orders->next;
|
||||||
|
free(orders);
|
||||||
|
orders = tmp;
|
||||||
|
}
|
||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */
|
/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/12/05 08:49:16 by tomoron ### ########.fr */
|
/* Updated: 2024/12/15 19:20:52 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -135,6 +135,7 @@ long int resolve_part2(char *input, char **split)
|
|||||||
{
|
{
|
||||||
(void)input;
|
(void)input;
|
||||||
t_orders *orders;
|
t_orders *orders;
|
||||||
|
t_orders *tmp;
|
||||||
long int res;
|
long int res;
|
||||||
|
|
||||||
orders = 0;
|
orders = 0;
|
||||||
@ -149,5 +150,11 @@ long int resolve_part2(char *input, char **split)
|
|||||||
res += check_line(*split, orders);
|
res += check_line(*split, orders);
|
||||||
split++;
|
split++;
|
||||||
}
|
}
|
||||||
|
while(orders)
|
||||||
|
{
|
||||||
|
tmp = orders->next;
|
||||||
|
free(orders);
|
||||||
|
orders = tmp;
|
||||||
|
}
|
||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user