-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #50 #52
Fix #50 #52
Conversation
Is Norminette rules changed after I quit 42? or did I just missed the test case? |
I don't believe the rules changed recently. The bug was just well hidden thanks to the discount system for |
See: #53 Code/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* push_swap.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yaassila <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/01 13:00:00 by yaassila #+# #+# */
/* Updated: 2023/02/14 18:00:00 by yaassila ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PUSH_SWAP_H
# define PUSH_SWAP_H
# include "libft.h"
# include <limits.h>
// --- Types ---
typedef struct s_node
{
int data;
struct s_node *prev;
struct s_node *next;
} t_node;
typedef struct s_stack
{
t_node *top;
t_node *bottom;
size_t size;
} t_stack;
typedef struct s_find_result
{
t_node *node;
size_t index;
} t_find_result;
typedef struct s_cost
{
size_t stack_a_index;
size_t stack_b_index;
int cost;
} t_cost;
// --- Prototypes ---
int parse_args(int argc, char const *argv[], t_stack *stack);
t_node *node_new(int data);
t_stack *stack_new(void);
void stack_free(t_stack *stack);
void stack_print(t_stack *stack);
t_find_result stack_find(t_stack *stack, int data);
t_find_result stack_find_min(t_stack *stack);
t_find_result stack_find_max(t_stack *stack);
t_node *stack_pop_top(t_stack *stack);
t_node *stack_pop_bottom(t_stack *stack);
void stack_push_top(t_stack *stack, t_node *node);
void stack_push_bottom(t_stack *stack, t_node *node);
void sa(t_stack *stack_a);
void sb(t_stack *stack_b);
void ss(t_stack *stack_a, t_stack *stack_b);
void pa(t_stack *stack_a, t_stack *stack_b);
void pb(t_stack *stack_a, t_stack *stack_b);
void ra(t_stack *stack_a);
void rb(t_stack *stack_b);
void rr(t_stack *stack_a, t_stack *stack_b);
void rra(t_stack *stack_a);
void rrb(t_stack *stack_b);
void rrr(t_stack *stack_a, t_stack *stack_b);
size_t get_rotate_count(t_stack *stack, size_t index);
t_bool are_rotations_same_direction(t_stack *stack_a,
t_stack *stack_b, size_t index_a, size_t index_b);
t_bool are_rotations_normal(t_stack *stack_a, t_stack *stack_b,
size_t index_a, size_t index_b);
void rotate_stack_to_index(t_stack *stack, size_t index,
void (*r)(t_stack *), void (*rr)(t_stack *));
void rotate_stacks_to_indices(t_stack *stack_a, t_stack *stack_b,
size_t index_a, size_t index_b);
t_bool is_stack_sorted_ascending(t_stack *stack);
void sort(t_stack *stack_a, t_stack *stack_b);
void three_sort(t_stack *stack_a);
void insertion_sort(t_stack *stack_a, t_stack *stack_b);
void min_cost_sort(t_stack *stack_a, t_stack *stack_b,
size_t insertion_sort_threshold);
#endif |
Fixes #50 by properly calculating the additional indent level:
The previous code assumed a paren depth of 1 meant 2 tabs. This is incorrect and the code made a few exceptions for control statements and return statements to correct for this behavior. Of course, this couldn't catch all possible code where this adjustment was needed.
The new code assumes a paren depth of 1 means 1 tab. Tab count starts increasing once the paren depth is at least 2. (Had to check norminette's code to find this behavior, it wasn't fun)
Also fixed a test case that was based on the previous (incorrect) behavior (and it indeed made the norminette complain)
Finally, made a line of the code clearer and removed an unused comment at the top of the test file.