Skip to content

Commit

Permalink
less errors still wont work
Browse files Browse the repository at this point in the history
  • Loading branch information
Ana Laura Da Silva Volkmann committed Jul 17, 2024
1 parent 62588ff commit 08efcbd
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 37 deletions.
19 changes: 12 additions & 7 deletions ft_big_sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ana-lda- <ana-lda-@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/10 12:54:58 by ana-lda- #+# #+# */
/* Updated: 2024/07/16 15:14:29 by ana-lda- ### ########.fr */
/* Updated: 2024/07/17 14:47:07 by ana-lda- ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -72,19 +72,24 @@ void send_b_to_a(t_stack **stack_a, t_stack **stack_b)
ft_pa(stack_a, stack_b, 0);
}

void sort_stack(t_stack **stack_a)
/* void lowest_on_top(t_stack **stack_a)
{
if (!is_sorted(*stack_a))
while (*stack_a != ft_lowest(stack_a))
{
ft_ra(stack_a, 0);
}
} */
void sort_stack(t_stack **stack_a, t_stack **stack_b)
{
t_stack **stack_b;

stack_b = NULL;
if (ft_list_size(*stack_a) == 2)
ft_sa(stack_a, 0);
else if (ft_list_size(*stack_a) == 3)
sort_three(stack_a);
if (ft_list_size(*stack_a) > 3 && !is_sorted(*stack_a))
ft_pb(&stack_b, stack_a, 0);
ft_pb(stack_b, stack_a, 0);
if (ft_list_size(*stack_a) > 3 && !is_sorted(*stack_a))
ft_pb(&stack_b, stack_a, 0);
ft_pb(stack_b, stack_a, 0);
while (ft_list_size(*stack_a) > 3)
{
update_stack_nodes(stack_a, stack_b, 1);
Expand Down
2 changes: 1 addition & 1 deletion libft/ft_printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ana-lda- <ana-lda-@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/04 19:50:50 by ana-lda- #+# #+# */
/* Updated: 2024/06/26 15:32:57 by ana-lda- ### ########.fr */
/* Updated: 2024/07/17 13:01:21 by ana-lda- ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
Binary file removed libft/libft.a
Binary file not shown.
8 changes: 5 additions & 3 deletions operations_stack_b.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ana-lda- <ana-lda-@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/09 12:45:59 by ana-lda- #+# #+# */
/* Updated: 2024/07/09 16:46:12 by ana-lda- ### ########.fr */
/* Updated: 2024/07/17 14:12:27 by ana-lda- ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -68,12 +68,14 @@ place it on top of 'b'. Do nothing if 'a' is empty.*/
void ft_pb(t_stack **stack_b, t_stack **stack_a, int i)
{
t_stack *temp;
t_stack *temp_a;

if (!stack_a || !(*stack_a))
return ;
temp = *stack_b;
*stack_b = *stack_a;
*stack_a = (*stack_a)->next;
temp_a = *stack_a;
*stack_b = temp_a;
*stack_a = (temp_a)->next;
if (*stack_a)
{
(*stack_a)->prev = NULL;
Expand Down
Binary file removed push_swap
Binary file not shown.
18 changes: 9 additions & 9 deletions push_swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ana-lda- <ana-lda-@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/27 14:18:34 by ana-lda- #+# #+# */
/* Updated: 2024/07/16 15:14:58 by ana-lda- ### ########.fr */
/* Updated: 2024/07/17 14:27:53 by ana-lda- ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -31,19 +31,19 @@ int main(int argc, char **argv)
stack_a = new_stack(argv);
if (!is_sorted(stack_a))
{
ft_pb(&stack_b, &stack_a, 0);
ft_pb(&stack_b, &stack_a, 0);
ft_pb(&stack_b, &stack_a, 0);
set_target_in_b(&stack_a, &stack_b);
//sort_stack(&stack_a);
sort_stack(&stack_a, &stack_b);
t_stack *temp;
t_stack *temp_b;
temp_b = stack_b;
temp = stack_a;
ft_printf("a |");
while (temp)
{
ft_printf("%d->", temp->data);
if (temp->target)
ft_printf("target: %d", temp->target->data);
ft_printf("\n");
//ft_printf("b | %d->\n", temp_b->data);
//if (temp->target)
//ft_printf("target: %d", temp->target->data);
//ft_printf("\n");
temp = temp->next;
}
}
Expand Down
4 changes: 2 additions & 2 deletions push_swap.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ana-lda- <ana-lda-@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/26 15:05:43 by ana-lda- #+# #+# */
/* Updated: 2024/07/16 15:14:29 by ana-lda- ### ########.fr */
/* Updated: 2024/07/17 14:15:41 by ana-lda- ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -76,7 +76,7 @@ void ft_rrr(t_stack **stack_a, t_stack **stack_b, int i);

/*......................BIG_SORT.........................*/

void sort_stack(t_stack **stack_a);
void sort_stack(t_stack **stack_a, t_stack **stack_b);
void sort_three(t_stack **stack_a);

/*......................SET_TARGETS........................*/
Expand Down
24 changes: 12 additions & 12 deletions set_cost_of.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ana-lda- <ana-lda-@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/16 13:38:28 by ana-lda- #+# #+# */
/* Updated: 2024/07/16 13:44:16 by ana-lda- ### ########.fr */
/* Updated: 2024/07/17 15:03:00 by ana-lda- ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -20,15 +20,15 @@ void index_median(t_stack **stack)
t_stack *temp;
int median;

median = ft_list_size(stack) / 2;
median = ft_list_size(*stack) / 2;
i = 0;
temp = *stack;
while (temp)
{
temp->index = i;
if (i > median)
if (i < median)
temp->above_median = true;
else if (i < median)
else if (i > median)
temp->above_median = false;
i++;
temp = temp->next;
Expand All @@ -37,14 +37,14 @@ void index_median(t_stack **stack)

void refine_cost(t_stack *temp, t_stack **stack_a, t_stack **stack_b)
{
int size_a = ft_list_size(stack_a);
int size_b = ft_list_size(stack_b);
int size_a = ft_list_size(*stack_a);
int size_b = ft_list_size(*stack_b);

if (temp->above_median && temp->target->above_median)
{
temp->cost -= (temp->index < temp->target->index) ? temp->index : tmp->target->index;
temp->cost -= (temp->index < temp->target->index) ? temp->index : temp->target->index;
}
else if (!temp->above_median && !temp->target->above_median)
else
{
int cost_a = size_a - temp->index;
int cost_b = size_b - temp->target->index;
Expand All @@ -64,11 +64,11 @@ void cost_of_a (t_stack **stack_a, t_stack **stack_b)
if (temp->above_median)
temp->cost = temp->index;
else
temp->cost = ft_list_size(stack_a) - temp->index;
temp->cost = ft_list_size(*stack_a) - temp->index;
if (temp->target->above_median)
temp->cost += temp->target->index;
else
temp->cost += ft_list_size(stack_b) - temp->target->index;
temp->cost += ft_list_size(*stack_b) - temp->target->index;
refine_cost(temp, stack_a, stack_b);
temp = temp->next;
}
Expand All @@ -84,11 +84,11 @@ void cost_of_b(t_stack **stack_a, t_stack **stack_b)
if (temp->above_median)
temp->cost = temp->index;
else
temp->cost = ft_list_size(stack_a) - temp->index;
temp->cost = ft_list_size(*stack_a) - temp->index;
if (temp->target->above_median)
temp->cost += temp->target->index;
else
temp->cost += ft_list_size(stack_b) - temp->target->index;
temp->cost += ft_list_size(*stack_b) - temp->target->index;
refine_cost(temp, stack_b, stack_a);
temp = temp->next;
}
Expand Down
6 changes: 3 additions & 3 deletions set_targets.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ana-lda- <ana-lda-@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/13 14:26:47 by ana-lda- #+# #+# */
/* Updated: 2024/07/16 15:05:59 by ana-lda- ### ########.fr */
/* Updated: 2024/07/17 15:13:20 by ana-lda- ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -43,7 +43,7 @@ void set_target_in_b(t_stack **stack_a, t_stack **stack_b)
}

/** @brief this funcion sets the best targets for each element
* of statck b in stack a; */
* of stack b in stack a; */
void set_target_in_a(t_stack **stack_a, t_stack **stack_b)
{
t_stack *temp_a;
Expand Down Expand Up @@ -74,7 +74,7 @@ void set_target_in_a(t_stack **stack_a, t_stack **stack_b)
void update_stack_nodes(t_stack **stack_a, t_stack **stack_b, int flag)
{
index_median(stack_a);
idex_median(stack_b);
index_median(stack_b);
if (flag == 1)
{
set_target_in_b(stack_a, stack_b);
Expand Down

0 comments on commit 08efcbd

Please sign in to comment.