-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstructions1.c
56 lines (50 loc) · 1.88 KB
/
instructions1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* instructions1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fatkeski <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/20 15:16:57 by fatkeski #+# #+# */
/* Updated: 2024/03/20 15:20:15 by fatkeski ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
/*stack'in en üstteki 2 elemanını swapler*/
void swap(t_list *stack, char stack_name)
{
int temp;
int temp_flag;
if ((stack->next == 0) || stack == 0)
return ;
temp = stack->content;
temp_flag = stack->flag;
stack->content = stack->next->content;
stack->flag = stack->next->flag;
stack->next->content = temp;
stack->next->flag = temp_flag;
if (stack_name == 'a')
write(1, "sa\n", 3);
if (stack_name == 'b')
write(1, "sb\n", 3);
}
/*2 stack'in en üstteki 2 elemanını swapler*/
void swap_stacks(t_list *stack_a, t_list *stack_b)
{
swap(stack_a, 'a');
swap(stack_b, 'b');
}
/*src stack'in en üstteki elemanı dest'in en üstüne konur*/
void push(t_list **stack_dest, t_list **stack_src, char stack_dest_name)
{
t_list *top_src;
if (stack_src == 0 || *stack_src == 0)
return ;
top_src = *stack_src;
*stack_src = (*stack_src)->next;
ft_lstadd_front(stack_dest, top_src);
if (stack_dest_name == 'a')
write(1, "pa\n", 3);
if (stack_dest_name == 'b')
write(1, "pb\n", 3);
}