Skip to content

Commit

Permalink
last
Browse files Browse the repository at this point in the history
  • Loading branch information
Vradss committed Apr 27, 2024
1 parent ce65845 commit 20a1ef3
Show file tree
Hide file tree
Showing 16 changed files with 158 additions and 137 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: vflorez <vflorez@student.42.fr> +#+ +:+ +#+ #
# By: vradis <vradis@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# 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 #
# #
# **************************************************************************** #

Expand Down Expand Up @@ -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
Expand Down
69 changes: 38 additions & 31 deletions includes/push_swap.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* push_swap.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vflorez <vflorez@student.42.fr> +#+ +:+ +#+ */
/* By: vradis <vradis@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -16,6 +16,7 @@
# include <unistd.h>
# include <stdio.h>
# include <stdlib.h>
# include <limits.h>
# include "../src/libft/libft.h"
# include "../src/Printf/ft_printf.h"

Expand All @@ -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
8 changes: 4 additions & 4 deletions src/free.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
/* ::: :::::::: */
/* free.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vflorez <vflorez@student.42.fr> +#+ +:+ +#+ */
/* By: vradis <vradis@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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)
{
Expand Down
22 changes: 11 additions & 11 deletions src/handle_args.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@
/* ::: :::::::: */
/* handle_args.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vflorez <vflorez@student.42.fr> +#+ +:+ +#+ */
/* By: vradis <vradis@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
}
return (1);
}

/*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)
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down
13 changes: 6 additions & 7 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vflorez <vflorez@student.42.fr> +#+ +:+ +#+ */
/* By: vradis <vradis@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

#include "push_swap.h"

int main(int argc, char *argv[])
{
t_stack_node *stack_a;
t_stack *stack_a;

stack_a = NULL;
int arg = 1;
Expand All @@ -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);
}
12 changes: 6 additions & 6 deletions src/push_actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
/* ::: :::::::: */
/* push_actions.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vflorez <vflorez@student.42.fr> +#+ +:+ +#+ */
/* By: vradis <vradis@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

#include "push_swap.h"

/*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)
{
Expand All @@ -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)
{
Expand Down
18 changes: 9 additions & 9 deletions src/reverse_rot_actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
/* ::: :::::::: */
/* reverse_rot_actions.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vflorez <vflorez@student.42.fr> +#+ +:+ +#+ */
/* By: vradis <vradis@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

#include "push_swap.h"

/*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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions src/rotate_actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
/* ::: :::::::: */
/* rotate_actions.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vflorez <vflorez@student.42.fr> +#+ +:+ +#+ */
/* By: vradis <vradis@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

#include "push_swap.h"

/*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)
{
Expand All @@ -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)
{
Expand All @@ -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);
Expand Down
Loading

0 comments on commit 20a1ef3

Please sign in to comment.