Skip to content

Commit

Permalink
implement nano_sort case 3
Browse files Browse the repository at this point in the history
  • Loading branch information
rask24 committed Jan 12, 2024
1 parent bb5e636 commit 3d8845f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
4 changes: 2 additions & 2 deletions 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 16:09:00 by reasuke ### ########.fr */
/* Updated: 2024/01/12 16:17:17 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

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

Expand All @@ -23,11 +23,40 @@ static void _handle_2(t_list *stack)
ft_putendl_fd("sa", STDOUT_FILENO);
}

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

first = ft_atoi(stack->content);
second = ft_atoi(stack->next->content);
third = ft_atoi(stack->next->next->content);
if (first == 2 && second == 1 && third == 3)
ft_putendl_fd("sa", STDOUT_FILENO);
else if (first == 3 && second == 2 && third == 1)
{
ft_putendl_fd("sa", STDOUT_FILENO);
ft_putendl_fd("rra", STDOUT_FILENO);
}
else if (first == 3 && second == 1 && third == 2)
ft_putendl_fd("ra", STDOUT_FILENO);
else if (first == 1 && second == 3 && third == 2)
{
ft_putendl_fd("sa", STDOUT_FILENO);
ft_putendl_fd("ra", STDOUT_FILENO);
}
else if (first == 2 && second == 3 && third == 1)
ft_putendl_fd("rra", 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);
else if (num_of_element == 3)
_handel_3(stack);
}

0 comments on commit 3d8845f

Please sign in to comment.