Skip to content

Commit

Permalink
implement nano_sort case 2
Browse files Browse the repository at this point in the history
  • Loading branch information
rask24 committed Jan 12, 2024
1 parent 20f8bc7 commit bb5e636
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ LIBFT_DIR = ./libft
SRC = $(SRC_DIR)/main.c \
$(SRC_DIR)/is_invalid_argument.c \
$(SRC_DIR)/generate_stack.c \
$(SRC_DIR)/nano_sort.c \
$(SRC_DIR)/utils/exit_with_error.c
OBJ = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SRC))
DEP = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.d, $(SRC))
Expand Down
4 changes: 3 additions & 1 deletion include/push_swap.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: reasuke <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/10 12:37:54 by reasuke #+# #+# */
/* Updated: 2024/01/11 19:35:24 by reasuke ### ########.fr */
/* Updated: 2024/01/12 16:02:39 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -27,6 +27,8 @@ bool is_invalid_argument(int argc, char **argv);

t_list *generate_stack(int argc, char **argv);

void nano_sort(t_list *stack, int argc);

void exit_with_error(void);

#endif
4 changes: 3 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: reasuke <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/10 12:37:36 by reasuke #+# #+# */
/* Updated: 2024/01/12 15:49:05 by reasuke ### ########.fr */
/* Updated: 2024/01/12 16:09:00 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -36,6 +36,8 @@ int main(int argc, char **argv)
if (is_invalid_argument(argc, argv))
exit_with_error();
stack_a = generate_stack(argc, argv);
if (argc < 4)
nano_sort(stack_a, argc);
ft_lstclear(&stack_a, free);
return (0);
}
33 changes: 33 additions & 0 deletions src/nano_sort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* nano_sort.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: reasuke <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/12 15:58:22 by reasuke #+# #+# */
/* Updated: 2024/01/12 16:08:17 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "push_swap.h"

static void _handle_2(t_list *stack)
{
int first;
int second;

first = ft_atoi(stack->content);
second = ft_atoi(stack->next->content);
if (first > second)
ft_putendl_fd("sa", STDOUT_FILENO);
}

void nano_sort(t_list *stack, int argc)
{
int num_of_element;

num_of_element = argc - 1;
if (num_of_element == 2)
_handle_2(stack);
}

0 comments on commit bb5e636

Please sign in to comment.