diff --git a/Makefile b/Makefile index 39eaea9..e7262cf 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,10 @@ # ::: :::::::: # # Makefile :+: :+: :+: # # +:+ +:+ +:+ # -# By: vflorez +#+ +:+ +#+ # +# By: vradis +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/10/02 17:28:00 by vflorez #+# #+# # -# Updated: 2024/01/19 16:06:27 by vflorez ### ########.fr # +# Updated: 2024/04/27 18:57:32 by vradis ### ########.fr # # # # **************************************************************************** # @@ -36,7 +36,8 @@ SRC_FILES = src/swap_actions.c\ src/sort_all.c\ src/stack_utils_2.c\ src/sort_10.c\ - src/sort_100.c + src/sort_100.c\ + src/sort_500.c\ LIBFT = $(SRC_DIR)/libft PRINTF = $(SRC_DIR)/Printf diff --git a/includes/push_swap.h b/includes/push_swap.h index 33afa3f..c594fcc 100644 --- a/includes/push_swap.h +++ b/includes/push_swap.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* push_swap.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: vflorez +#+ +:+ +#+ */ +/* By: vradis +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/10/04 16:14:44 by vflorez #+# #+# */ -/* Updated: 2024/04/25 18:05:15 by vflorez ### ########.fr */ +/* Updated: 2024/04/27 19:03:47 by vradis ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,7 @@ # include # include # include +# include # include "../src/libft/libft.h" # include "../src/Printf/ft_printf.h" @@ -26,47 +27,53 @@ typedef struct stack_node int data; int index; struct stack_node *next; -} t_stack_node; +} t_stack; /*Handle erros in argvs*/ -int check_limits(t_stack_node **stack); -int check_duplicate(t_stack_node **stack); +int check_limits(t_stack **stack); +int check_duplicate(t_stack **stack); int check_str(char *str); /*Error & free stacks*/ -void ft_free(t_stack_node *stack); +void ft_free(t_stack *stack); /*Stacks Utils*/ -int stack_size(t_stack_node *stack); -void add_node_end(t_stack_node **stack, t_stack_node *newnode); -void printStack(const char *name, t_stack_node *stack); -void ft_node_index(t_stack_node **stack_a, int data); -int ft_stack_organized(t_stack_node *stack); -int ft_lowest_index(t_stack_node **stack); -void ft_rra_pb(t_stack_node **stack_a, t_stack_node **stack_b, int index); -void ft_ra_pb(t_stack_node **stack_a, t_stack_node **stack_b, int index); -int ft_highest_index(t_stack_node **stack); -t_stack_node*add_newnode(t_stack_node *stack_a, int data); +int stack_size(t_stack *stack); +void add_node_end(t_stack **stack, t_stack *newnode); +void ft_node_index(t_stack **stack_a, int data); +int ft_stack_organized(t_stack *stack); +int ft_lowest_index(t_stack **stack); +void ft_rra_pb(t_stack **stack_a, t_stack **stack_b, int index); +void ft_ra_pb(t_stack **stack_a, t_stack **stack_b, int index); +int ft_highest_index(t_stack **stack); +t_stack*add_newnode(t_stack *stack_a, int data); +int ft_data_limit(t_stack **stack_a, int limit_data); +void ft_pb_chunk(t_stack **stack_a, t_stack **stack_b, int data); +void ft_rb_pa(t_stack **stack_a, t_stack **stack_b, int index); +void ft_rrb_pa(t_stack **stack_a, t_stack **stack_b, int index); + + /*Actions allowed*/ -void ft_sa(t_stack_node **stack_a); -void ft_sb(t_stack_node **stack_b); -void ft_ss(t_stack_node **stack_a, t_stack_node **stack_b); +void ft_sa(t_stack **stack_a); +void ft_sb(t_stack **stack_b); +void ft_ss(t_stack **stack_a, t_stack **stack_b); //----- -void ft_ra(t_stack_node **stack_a); -void ft_rb(t_stack_node **stack_b); -void ft_rr(t_stack_node **stack_a, t_stack_node **stack_b); +void ft_ra(t_stack **stack_a); +void ft_rb(t_stack **stack_b); +void ft_rr(t_stack **stack_a, t_stack **stack_b); //----- -void ft_rra(t_stack_node **stack_a); -void ft_rrb(t_stack_node **stack_b); -void ft_rrr(t_stack_node **stack_a, t_stack_node **stack_b); +void ft_rra(t_stack **stack_a); +void ft_rrb(t_stack **stack_b); +void ft_rrr(t_stack **stack_a, t_stack **stack_b); //----- -void ft_pa(t_stack_node **stack_a, t_stack_node **stack_b); -void ft_pb(t_stack_node **stack_a, t_stack_node **stack_b); +void ft_pa(t_stack **stack_a, t_stack **stack_b); +void ft_pb(t_stack **stack_a, t_stack **stack_b); /*Sort numbers*/ -void ft_sort_3(t_stack_node **stack); -void ft_sort_10(t_stack_node **stack_a, t_stack_node **stack_b); -void ft_sort_100(t_stack_node **stack_a, t_stack_node **stack_b, int high_data); -void ft_sort_all(t_stack_node **stack_a); +void ft_sort_3(t_stack **stack); +void ft_sort_10(t_stack **stack_a, t_stack **stack_b); +void ft_sort_100(t_stack **stack_a, t_stack **stack_b, int high_data); +void ft_sort_500(t_stack **stack_a, t_stack **stack_b, int high_data); +void ft_sort_all(t_stack **stack_a); #endif \ No newline at end of file diff --git a/src/free.c b/src/free.c index ee83523..141dd78 100644 --- a/src/free.c +++ b/src/free.c @@ -3,19 +3,19 @@ /* ::: :::::::: */ /* free.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: vflorez +#+ +:+ +#+ */ +/* By: vradis +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/13 13:02:38 by vflorez #+# #+# */ -/* Updated: 2024/04/25 15:47:41 by vflorez ### ########.fr */ +/* Updated: 2024/04/27 18:39:37 by vradis ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" /*This functions free memory in stack*/ -void ft_free(t_stack_node *stack) +void ft_free(t_stack *stack) { - t_stack_node *ptr; + t_stack *ptr; while (stack != NULL) { diff --git a/src/handle_args.c b/src/handle_args.c index 4ddd100..4ac5e29 100644 --- a/src/handle_args.c +++ b/src/handle_args.c @@ -3,26 +3,26 @@ /* ::: :::::::: */ /* handle_args.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: vflorez +#+ +:+ +#+ */ +/* By: vradis +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/27 20:50:18 by vflorez #+# #+# */ -/* Updated: 2024/04/25 18:09:59 by vflorez ### ########.fr */ +/* Updated: 2024/04/27 19:04:07 by vradis ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" /*Function checks data int_limits */ -int check_limits(t_stack_node **stack) +int check_limits(t_stack **stack) { - t_stack_node *newnode; + t_stack *newnode; newnode = *stack; while (newnode != NULL) { - if (newnode->data > 2147483647 || newnode->data < -2147483648) + if (newnode->data > INT_MAX || newnode->data < INT_MIN) { - return (ft_printf("Error with limits\n"), 0); + return (ft_printf("Error\n"), 0); } newnode = newnode->next; } @@ -30,10 +30,10 @@ int check_limits(t_stack_node **stack) } /*Function checks repeat or duplicate data nodes*/ -int check_duplicate(t_stack_node **stack) +int check_duplicate(t_stack **stack) { - t_stack_node *newnode; - t_stack_node *duplicate; + t_stack *newnode; + t_stack *duplicate; newnode = *stack; if (check_limits(stack) != 1 || newnode == NULL) @@ -45,7 +45,7 @@ int check_duplicate(t_stack_node **stack) { if (newnode->data == duplicate->data) { - return (ft_printf("Error with duplicates\n"), 0); + return (ft_printf("Error\n"), 0); } duplicate = duplicate->next; } @@ -71,7 +71,7 @@ int check_str(char *str) return (1); } -void ft_handle_parsing(char *str, t_stack_node **stack_a) +void ft_handle_parsing(char *str, t_stack **stack_a) { char *ptr; int data; diff --git a/src/main.c b/src/main.c index 8dae5e3..5cafe41 100644 --- a/src/main.c +++ b/src/main.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: vflorez +#+ +:+ +#+ */ +/* By: vradis +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/27 20:06:07 by vflorez #+# #+# */ -/* Updated: 2024/04/25 18:12:13 by vflorez ### ########.fr */ +/* Updated: 2024/04/27 18:53:52 by vradis ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ int main(int argc, char *argv[]) { - t_stack_node *stack_a; + t_stack *stack_a; stack_a = NULL; int arg = 1; @@ -27,16 +27,15 @@ int main(int argc, char *argv[]) ft_node_index(&stack_a, value); if(!check_limits(&stack_a) || !check_duplicate(&stack_a) || !check_str(argv[arg])) { - ft_printf("invalid input"); ft_free(stack_a); return (1); } arg++; } if (!ft_stack_organized(stack_a)) - ft_sort_all(&stack_a); - - //printStack("Final A", stack_a); + { + ft_sort_all(&stack_a); + } ft_free(stack_a); return (0); } diff --git a/src/push_actions.c b/src/push_actions.c index a2d1449..0990c57 100644 --- a/src/push_actions.c +++ b/src/push_actions.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* push_actions.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: vflorez +#+ +:+ +#+ */ +/* By: vradis +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/14 10:37:41 by vradis #+# #+# */ -/* Updated: 2024/04/25 15:49:46 by vflorez ### ########.fr */ +/* Updated: 2024/04/27 18:39:37 by vradis ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,9 +14,9 @@ /*Function that take the first element at the top of stack B and put it at the top of stack A*/ -void ft_pa(t_stack_node **stack_a, t_stack_node **stack_b) +void ft_pa(t_stack **stack_a, t_stack **stack_b) { - t_stack_node *ptr; + t_stack *ptr; if (stack_size(*stack_b) > 0) { @@ -30,9 +30,9 @@ void ft_pa(t_stack_node **stack_a, t_stack_node **stack_b) /*Function that take the first element at the top of stack A and put it at the top of stack B*/ -void ft_pb(t_stack_node **stack_a, t_stack_node **stack_b) +void ft_pb(t_stack **stack_a, t_stack **stack_b) { - t_stack_node *ptr; + t_stack *ptr; if (stack_size(*stack_a) > 0) { diff --git a/src/reverse_rot_actions.c b/src/reverse_rot_actions.c index 8b694aa..350dfa3 100644 --- a/src/reverse_rot_actions.c +++ b/src/reverse_rot_actions.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* reverse_rot_actions.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: vflorez +#+ +:+ +#+ */ +/* By: vradis +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/14 13:26:44 by vradis #+# #+# */ -/* Updated: 2024/04/25 15:51:42 by vflorez ### ########.fr */ +/* Updated: 2024/04/27 18:39:37 by vradis ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,10 +14,10 @@ /*Function which the last element becomes the first element in stack A*/ -void ft_rra(t_stack_node **stack_a) +void ft_rra(t_stack **stack_a) { - t_stack_node *ptr; - t_stack_node *lastnode; + t_stack *ptr; + t_stack *lastnode; ptr = *stack_a; lastnode = NULL; @@ -37,10 +37,10 @@ void ft_rra(t_stack_node **stack_a) /*Function which the last element becomes the first element in stack B*/ -void ft_rrb(t_stack_node **stack_b) +void ft_rrb(t_stack **stack_b) { - t_stack_node *ptr; - t_stack_node *lastnode; + t_stack *ptr; + t_stack *lastnode; ptr = *stack_b; lastnode = NULL; @@ -59,7 +59,7 @@ void ft_rrb(t_stack_node **stack_b) } /*Function that runs rra & rrb at the same time*/ -void ft_rrr(t_stack_node **stack_a, t_stack_node **stack_b) +void ft_rrr(t_stack **stack_a, t_stack **stack_b) { ft_rra(stack_a); ft_rrb(stack_b); diff --git a/src/rotate_actions.c b/src/rotate_actions.c index bfe6dde..4af4e35 100644 --- a/src/rotate_actions.c +++ b/src/rotate_actions.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* rotate_actions.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: vflorez +#+ +:+ +#+ */ +/* By: vradis +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/14 11:21:00 by vradis #+# #+# */ -/* Updated: 2024/04/25 15:53:45 by vflorez ### ########.fr */ +/* Updated: 2024/04/27 18:39:37 by vradis ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,9 +14,9 @@ /*Function which the first element becomes the last element in stack A*/ -void ft_ra(t_stack_node **stack_a) +void ft_ra(t_stack **stack_a) { - t_stack_node *ptr; + t_stack *ptr; if (stack_size(*stack_a) > 1) { @@ -30,9 +30,9 @@ void ft_ra(t_stack_node **stack_a) /*Function which the first element becomes the last element in stack B*/ -void ft_rb(t_stack_node **stack_b) +void ft_rb(t_stack **stack_b) { - t_stack_node *ptr; + t_stack *ptr; if (stack_size(*stack_b) > 1) { @@ -45,7 +45,7 @@ void ft_rb(t_stack_node **stack_b) } /*Function that runs ft_ra and ft_rb at the same time*/ -void ft_rr(t_stack_node **stack_a, t_stack_node **stack_b) +void ft_rr(t_stack **stack_a, t_stack **stack_b) { ft_ra(stack_a); ft_rb(stack_b); diff --git a/src/sort_10.c b/src/sort_10.c index 4106fc3..c10c6cc 100644 --- a/src/sort_10.c +++ b/src/sort_10.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* sort_10.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: vflorez +#+ +:+ +#+ */ +/* By: vradis +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/27 18:13:55 by vradis #+# #+# */ -/* Updated: 2024/01/19 16:21:13 by vflorez ### ########.fr */ +/* Updated: 2024/04/27 18:39:37 by vradis ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ /*Function which the first element becomes the last element in stack A and push it to Stack B*/ -void ft_ra_pb(t_stack_node **stack_a, t_stack_node **stack_b, int index) +void ft_ra_pb(t_stack **stack_a, t_stack **stack_b, int index) { while (index > 1) { @@ -26,7 +26,7 @@ void ft_ra_pb(t_stack_node **stack_a, t_stack_node **stack_b, int index) /*Function which the bottom element becomes the first element in stack A and push it to Stack B*/ -void ft_rra_pb(t_stack_node **stack_a, t_stack_node **stack_b, int index) +void ft_rra_pb(t_stack **stack_a, t_stack **stack_b, int index) { while (index <= stack_size(*stack_a)) { @@ -36,7 +36,7 @@ void ft_rra_pb(t_stack_node **stack_a, t_stack_node **stack_b, int index) ft_pb (stack_a, stack_b); } -void ft_sort_10(t_stack_node **stack_a, t_stack_node **stack_b) +void ft_sort_10(t_stack **stack_a, t_stack **stack_b) { int index; diff --git a/src/sort_100.c b/src/sort_100.c index e624eed..003920a 100644 --- a/src/sort_100.c +++ b/src/sort_100.c @@ -6,7 +6,7 @@ /* By: vradis +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/18 18:19:33 by vflorez #+# #+# */ -/* Updated: 2024/04/26 17:13:47 by vradis ### ########.fr */ +/* Updated: 2024/04/27 18:39:37 by vradis ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,9 +14,9 @@ /*This function counts how many elements in stack_a have an index equal to or less than limit_data*/ -int ft_data_limit(t_stack_node **stack_a, int limit_data) +int ft_data_limit(t_stack **stack_a, int limit_data) { - t_stack_node *ptr; + t_stack *ptr; int i; ptr = *stack_a; @@ -32,7 +32,7 @@ int ft_data_limit(t_stack_node **stack_a, int limit_data) /*This function pushes a chunk of elements of stack_a to stack_b based on data_limit*/ -void ft_pb_chunk(t_stack_node **stack_a, t_stack_node **stack_b, int data) +void ft_pb_chunk(t_stack **stack_a, t_stack **stack_b, int data) { int i; @@ -49,7 +49,7 @@ void ft_pb_chunk(t_stack_node **stack_a, t_stack_node **stack_b, int data) } } -void ft_rb_pa(t_stack_node **stack_a, t_stack_node **stack_b, int index) +void ft_rb_pa(t_stack **stack_a, t_stack **stack_b, int index) { while (index > 1) { @@ -59,7 +59,7 @@ void ft_rb_pa(t_stack_node **stack_a, t_stack_node **stack_b, int index) ft_pa(stack_a, stack_b); } -void ft_rrb_pa(t_stack_node **stack_a, t_stack_node **stack_b, int index) +void ft_rrb_pa(t_stack **stack_a, t_stack **stack_b, int index) { while (index <= stack_size(*stack_b)) { @@ -69,7 +69,7 @@ void ft_rrb_pa(t_stack_node **stack_a, t_stack_node **stack_b, int index) ft_pa(stack_a, stack_b); } -void ft_sort_100(t_stack_node **stack_a, t_stack_node **stack_b, int high_data) +void ft_sort_100(t_stack **stack_a, t_stack **stack_b, int high_data) { int chunk; int high_index; diff --git a/src/sort_3.c b/src/sort_3.c index a4106c1..c982e18 100644 --- a/src/sort_3.c +++ b/src/sort_3.c @@ -3,16 +3,16 @@ /* ::: :::::::: */ /* sort_3.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: vflorez +#+ +:+ +#+ */ +/* By: vradis +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/18 10:56:19 by vflorez #+# #+# */ -/* Updated: 2024/01/16 16:17:24 by vflorez ### ########.fr */ +/* Updated: 2024/04/27 18:39:37 by vradis ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" -void ft_sort_3(t_stack_node **stack) +void ft_sort_3(t_stack **stack) { int top; int middle; diff --git a/src/sort_500.c b/src/sort_500.c index 51aba0e..fd3642b 100644 --- a/src/sort_500.c +++ b/src/sort_500.c @@ -6,7 +6,32 @@ /* By: vradis +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/26 13:20:17 by vradis #+# #+# */ -/* Updated: 2024/04/26 13:20:18 by vradis ### ########.fr */ +/* Updated: 2024/04/27 18:39:37 by vradis ### ########.fr */ /* */ /* ************************************************************************** */ +#include + +void ft_sort_500(t_stack **stack_a, t_stack **stack_b, int high_data) +{ + int chunk; + int high_index; + int low_data; + + (void)stack_b; + low_data = 1; + chunk = high_data / 11; + while(stack_size(*stack_a) > 0) + { + ft_pb_chunk(stack_a, stack_b, low_data); + low_data = low_data + chunk; + } + while (stack_size(*stack_b) > 0) + { + high_index = ft_highest_index(stack_b); + if (high_index <= (stack_size(*stack_b) / 2)) + ft_rb_pa(stack_a, stack_b, high_index); + else if (high_index > (stack_size(*stack_b) / 2)) + ft_rrb_pa(stack_a, stack_b, high_index); + } +} \ No newline at end of file diff --git a/src/sort_all.c b/src/sort_all.c index dc3ee7f..0655deb 100644 --- a/src/sort_all.c +++ b/src/sort_all.c @@ -3,18 +3,18 @@ /* ::: :::::::: */ /* sort_all.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: vflorez +#+ +:+ +#+ */ +/* By: vradis +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/20 17:44:03 by vflorez #+# #+# */ -/* Updated: 2024/04/25 15:54:33 by vflorez ### ########.fr */ +/* Updated: 2024/04/27 18:56:39 by vradis ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" -void ft_sort_all(t_stack_node **stack_a) +void ft_sort_all(t_stack **stack_a) { - t_stack_node *stack_b; + t_stack *stack_b; int stack_size_a; stack_b = NULL; @@ -27,4 +27,6 @@ void ft_sort_all(t_stack_node **stack_a) ft_sort_10(stack_a, &stack_b); if (stack_size_a > 10 && stack_size_a <= 100) ft_sort_100(stack_a, &stack_b, stack_size_a); + if (stack_size_a > 101 && stack_size_a <= 500) + ft_sort_500(stack_a, &stack_b, stack_size_a); } diff --git a/src/stack_utils.c b/src/stack_utils.c index 3e7746a..6ad8ed7 100644 --- a/src/stack_utils.c +++ b/src/stack_utils.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* stack_utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: vflorez +#+ +:+ +#+ */ +/* By: vradis +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/14 08:12:33 by vradis #+# #+# */ -/* Updated: 2024/04/25 18:09:54 by vflorez ### ########.fr */ +/* Updated: 2024/04/27 18:48:29 by vradis ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ #include "Printf/ft_printf.h" /*Function that calculates the stack length*/ -int stack_size(t_stack_node *stack) +int stack_size(t_stack *stack) { int len; @@ -29,13 +29,12 @@ int stack_size(t_stack_node *stack) return (len); } return (0); - printf("Error al calcular stack_size"); } /*Add node at the end of the stack*/ -void add_node_end(t_stack_node **stack, t_stack_node *newnode) +void add_node_end(t_stack **stack, t_stack *newnode) { - t_stack_node *ptr; + t_stack *ptr; ptr = *stack; if (*stack == NULL) @@ -51,25 +50,13 @@ void add_node_end(t_stack_node **stack, t_stack_node *newnode) } } -/*Function that prints stacks*/ -void printStack(const char* name, t_stack_node *stack) -{ - ft_printf("Stack %s: ", name); - while (stack != NULL) - { - ft_printf("%d -> ", stack->data); - stack = stack->next; - } - ft_printf("NULL\n"); -} - /*Function creates a new node to add in stack and initialize the alias index in 1 */ -t_stack_node *add_newnode(t_stack_node *stack_a, int data) +t_stack *add_newnode(t_stack *stack_a, int data) { - t_stack_node *newnode; + t_stack *newnode; - newnode = malloc(sizeof(t_stack_node)); + newnode = malloc(sizeof(t_stack)); if (newnode == NULL) { ft_free(stack_a); @@ -85,10 +72,10 @@ t_stack_node *add_newnode(t_stack_node *stack_a, int data) 1. Create a newnode 2. Create the alias index in each node or data and it will help to organize the stack */ -void ft_node_index(t_stack_node **stack_a, int data) +void ft_node_index(t_stack **stack_a, int data) { - t_stack_node *newnode; - t_stack_node *ptr; + t_stack *newnode; + t_stack *ptr; newnode = add_newnode(*stack_a, data); if (*stack_a == NULL) @@ -117,9 +104,9 @@ from smallest to largest Return 1 = Organized Return 0 = Not Organized*/ -int ft_stack_organized(t_stack_node *stack) +int ft_stack_organized(t_stack *stack) { - t_stack_node *ptr; + t_stack *ptr; ptr = stack; while (ptr != NULL) diff --git a/src/stack_utils_2.c b/src/stack_utils_2.c index afdf5f0..f5e6860 100644 --- a/src/stack_utils_2.c +++ b/src/stack_utils_2.c @@ -3,19 +3,19 @@ /* ::: :::::::: */ /* stack_utils_2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: vflorez +#+ +:+ +#+ */ +/* By: vradis +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/27 14:08:37 by vradis #+# #+# */ -/* Updated: 2024/04/25 12:45:33 by vflorez ### ########.fr */ +/* Updated: 2024/04/27 18:39:37 by vradis ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" /*Function that returns the position of the lowest index*/ -int ft_lowest_index(t_stack_node **stack) +int ft_lowest_index(t_stack **stack) { - t_stack_node *ptr; + t_stack *ptr; int low_index; int low_data; int i; @@ -38,9 +38,9 @@ int ft_lowest_index(t_stack_node **stack) } /*Function that returns the position of the highest index*/ -int ft_highest_index(t_stack_node **stack) +int ft_highest_index(t_stack **stack) { - t_stack_node *ptr; + t_stack *ptr; int high_index; int high_data; int i; diff --git a/src/swap_actions.c b/src/swap_actions.c index efaf415..fb56874 100644 --- a/src/swap_actions.c +++ b/src/swap_actions.c @@ -3,19 +3,19 @@ /* ::: :::::::: */ /* swap_actions.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: vflorez +#+ +:+ +#+ */ +/* By: vradis +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/13 13:26:11 by vflorez #+# #+# */ -/* Updated: 2024/01/18 18:21:30 by vflorez ### ########.fr */ +/* Updated: 2024/04/27 18:39:37 by vradis ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" /*Function swap top 2 numbers in Stack A*/ -void ft_sa(t_stack_node **stack_a) +void ft_sa(t_stack **stack_a) { - t_stack_node *ptr; + t_stack *ptr; if (stack_size(*stack_a) >= 2) { @@ -28,9 +28,9 @@ void ft_sa(t_stack_node **stack_a) } /*Function swap top 2 numbers in Stack B*/ -void ft_sb(t_stack_node **stack_b) +void ft_sb(t_stack **stack_b) { - t_stack_node *ptr; + t_stack *ptr; if (stack_size(*stack_b) >= 2) { @@ -43,7 +43,7 @@ void ft_sb(t_stack_node **stack_b) } /*Function that runs ft_sa and ft_sb at the same time*/ -void ft_ss(t_stack_node **stack_a, t_stack_node **stack_b) +void ft_ss(t_stack **stack_a, t_stack **stack_b) { ft_sa(stack_a); ft_sb(stack_b);