update
This commit is contained in:
parent
f3f0588290
commit
d52896c79d
2 changed files with 22 additions and 28 deletions
2
mecstd
2
mecstd
|
|
@ -1 +1 @@
|
|||
Subproject commit e9c4ce89ea79ba399f8995f3c14e66e78555661d
|
||||
Subproject commit 60b9db4c20aa957cff32ae58dfc8a2124f9b35d5
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/01 21:00:12 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/02/08 18:44:58 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/02/08 18:53:49 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -19,32 +19,28 @@
|
|||
#include "me/vec/vec_i64_bool.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#define TESTER_ERROR(s) ""
|
||||
void sort_3(t_state *state);
|
||||
void sort_2(t_state *state);
|
||||
void sort_5(t_state *state);
|
||||
|
||||
// #define TESTER_ERROR(s) s
|
||||
void run_with_items(t_state *state);
|
||||
|
||||
void sort_3(t_state *state);
|
||||
void sort_2(t_state *state);
|
||||
void sort_5(t_state *state);
|
||||
|
||||
void run_with_items(t_state *state);
|
||||
|
||||
bool sort_i64_bool(t_i64_bool *lhs, t_i64_bool *rhs)
|
||||
bool sort_i64_bool(t_i64_bool *lhs, t_i64_bool *rhs)
|
||||
{
|
||||
return (lhs->value <= rhs->value);
|
||||
}
|
||||
|
||||
void free_state(t_state state)
|
||||
void free_state(t_state state)
|
||||
{
|
||||
vec_i64_free(state.stack_a);
|
||||
vec_i64_free(state.stack_b);
|
||||
vec_i64_bool_free(state.sorted);
|
||||
}
|
||||
|
||||
bool duplicate_check(t_state *state)
|
||||
bool duplicate_check(t_state *state)
|
||||
{
|
||||
t_i64 last;
|
||||
t_usize index;
|
||||
t_usize index;
|
||||
|
||||
if (state->sorted.len == 0)
|
||||
return (false);
|
||||
|
|
@ -59,11 +55,11 @@ bool duplicate_check(t_state *state)
|
|||
return (false);
|
||||
}
|
||||
|
||||
t_state parses_arguments(t_usize count, t_str nums[])
|
||||
t_state parses_arguments(t_usize count, t_str nums[])
|
||||
{
|
||||
t_state state;
|
||||
t_state state;
|
||||
t_i32 atoi;
|
||||
t_usize i;
|
||||
t_usize i;
|
||||
|
||||
state.stack_a = vec_i64_new(count, NULL);
|
||||
state.stack_b = vec_i64_new(count, NULL);
|
||||
|
|
@ -72,33 +68,31 @@ t_state parses_arguments(t_usize count, t_str nums[])
|
|||
while (i < count)
|
||||
{
|
||||
if (str_to_i32(nums[i], 10, &atoi))
|
||||
(free_state(state),
|
||||
me_eprintf("Error\n" TESTER_ERROR("Invalid Number\n")), exit(1));
|
||||
(free_state(state), me_eprintf("Error:\nInvalid Number\n"),
|
||||
exit(1));
|
||||
vec_i64_push(&state.stack_a, atoi);
|
||||
vec_i64_bool_push(&state.sorted,
|
||||
(t_i64_bool){.value = atoi, .active = false});
|
||||
vec_i64_bool_push(&state.sorted, (t_i64_bool){.value = atoi,
|
||||
.active = false});
|
||||
i++;
|
||||
}
|
||||
vec_i64_bool_sort(&state.sorted, sort_i64_bool);
|
||||
if (duplicate_check(&state))
|
||||
(free_state(state),
|
||||
me_eprintf("Error\n" TESTER_ERROR("Duplicate Number\n")), exit(1));
|
||||
(free_state(state), me_eprintf("Error:\nDuplicate Number\n"), exit(1));
|
||||
return (state);
|
||||
}
|
||||
|
||||
bool is_sorted(t_vec_i64 *v);
|
||||
bool is_sorted(t_vec_i64 *v);
|
||||
|
||||
int main(t_i32 argc, t_str argv[])
|
||||
int main(t_i32 argc, t_str argv[])
|
||||
{
|
||||
t_state state;
|
||||
t_state state;
|
||||
|
||||
(void)(argc--, argv++);
|
||||
state = parses_arguments(argc, argv);
|
||||
if (is_sorted(&state.stack_a))
|
||||
return (free_state(state), 0);
|
||||
if (state.stack_a.len == 0)
|
||||
(free_state(state), me_eprintf("Error\n" TESTER_ERROR("No Input\n")),
|
||||
exit(1));
|
||||
(free_state(state), me_eprintf("Error:\nNo Input\n"), exit(1));
|
||||
if (state.stack_a.len == 2)
|
||||
sort_2(&state);
|
||||
else if (state.stack_a.len == 3)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue