-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
214 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* initialization.h :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/02/11 12:30:37 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/11 12:33:50 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef INITIALIZATION_H | ||
# define INITIALIZATION_H | ||
|
||
# include "push_swap.h" | ||
|
||
int check_args(int argc, char **argv); | ||
t_stack *generate_stack(int argc, char **argv); | ||
void exit_with_error(void); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* large_sort.h :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/02/11 12:36:38 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/11 12:37:50 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef LARGE_SORT_H | ||
# define LARGE_SORT_H | ||
|
||
# include "push_swap.h" | ||
|
||
void large_sort(t_stack **p_a, t_stack **p_b); | ||
void set_cost(t_stack **p_a, t_stack **p_b); | ||
void set_opt(t_stack **p_b); | ||
void greedy_operation(t_stack **p_a, t_stack **p_b); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,81 +6,19 @@ | |
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/10 12:37:54 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/10 21:18:02 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/11 12:58:12 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef PUSH_SWAP_H | ||
# define PUSH_SWAP_H | ||
|
||
# include "../libft/libft.h" | ||
# include "types.h" | ||
# include "utils.h" | ||
# include <limits.h> | ||
# include <stdbool.h> | ||
# include <stdlib.h> | ||
# include <unistd.h> | ||
|
||
typedef t_list t_stack; | ||
|
||
typedef enum e_method | ||
{ | ||
INIT, | ||
FF, | ||
FR, | ||
RF, | ||
RR, | ||
} t_method; | ||
|
||
typedef struct s_content | ||
{ | ||
int index; | ||
int sf_cost; | ||
int sr_cost; | ||
int if_cost; | ||
int ir_cost; | ||
int min_cost; | ||
t_method opt_method; | ||
bool is_opt; | ||
} t_content; | ||
|
||
int check_args(int argc, char **argv); | ||
t_stack *generate_stack(int argc, char **argv); | ||
void exit_with_error(void); | ||
|
||
void sort(t_stack **p_a, t_stack **p_b); | ||
void nano_sort(t_stack **p_a); | ||
void micro_sort(t_stack **p_a, t_stack **p_b); | ||
void large_sort(t_stack **p_a, t_stack **p_b); | ||
void set_cost(t_stack **p_a, t_stack **p_b); | ||
void set_opt(t_stack **p_b); | ||
void greedy_operation(t_stack **p_a, t_stack **p_b); | ||
bool is_sorted_stack(t_stack *st); | ||
|
||
void operate_sa(t_stack **p_a); | ||
void operate_sb(t_stack **p_b); | ||
void operate_ss(t_stack **p_a, t_stack **p_b); | ||
void operate_ra(t_stack **p_a); | ||
void operate_rb(t_stack **p_b); | ||
void operate_rr(t_stack **p_a, t_stack **p_b); | ||
void operate_rra(t_stack **p_a); | ||
void operate_rrb(t_stack **p_a); | ||
void operate_rrr(t_stack **p_a, t_stack **p_b); | ||
void operate_pa(t_stack **p_b, t_stack **p_a); | ||
void operate_pb(t_stack **p_a, t_stack **p_b); | ||
void do_single_n_operations(t_stack **p_st, int n, | ||
void (*operation)(t_stack **)); | ||
void do_double_n_operations(t_stack **p_a, t_stack **p_b, int n, | ||
void (*operation)(t_stack **, t_stack **)); | ||
|
||
void push_stack(t_stack **p_s1, t_stack **p_s2); | ||
void swap_stack(t_stack **p_stack); | ||
void rotate_stack(t_stack **p_stack); | ||
void reverse_rotate_stack(t_stack **p_stack); | ||
|
||
void clear_stack(t_stack **p_stack, void (*del)(void *)); | ||
t_content *get_content(t_stack *st); | ||
int get_first_index(t_stack **p_stack); | ||
int get_second_index(t_stack **p_stack); | ||
int get_third_index(t_stack **p_stack); | ||
int stack_size(t_stack *stack); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* sort.h :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/02/11 12:42:03 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/11 12:45:45 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef SORT_H | ||
# define SORT_H | ||
|
||
# include "push_swap.h" | ||
|
||
void sort(t_stack **p_a, t_stack **p_b); | ||
void nano_sort(t_stack **p_a); | ||
void micro_sort(t_stack **p_a, t_stack **p_b); | ||
void large_sort(t_stack **p_a, t_stack **p_b); | ||
bool is_sorted_stack(t_stack *st); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* stack_operations.h :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/02/11 12:41:01 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/11 12:41:49 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef STACK_OPERATIONS_H | ||
# define STACK_OPERATIONS_H | ||
|
||
# include "push_swap.h" | ||
|
||
void operate_sa(t_stack **p_a); | ||
|
||
void operate_sb(t_stack **p_b); | ||
void operate_ss(t_stack **p_a, t_stack **p_b); | ||
void operate_ra(t_stack **p_a); | ||
void operate_rb(t_stack **p_b); | ||
void operate_rr(t_stack **p_a, t_stack **p_b); | ||
void operate_rra(t_stack **p_a); | ||
void operate_rrb(t_stack **p_a); | ||
void operate_rrr(t_stack **p_a, t_stack **p_b); | ||
void operate_pa(t_stack **p_b, t_stack **p_a); | ||
void operate_pb(t_stack **p_a, t_stack **p_b); | ||
void do_single_n_operations(t_stack **p_st, int n, | ||
void (*operation)(t_stack **)); | ||
void do_double_n_operations(t_stack **p_a, t_stack **p_b, int n, | ||
void (*operation)(t_stack **, t_stack **)); | ||
|
||
void push_stack(t_stack **p_s1, t_stack **p_s2); | ||
void swap_stack(t_stack **p_stack); | ||
void rotate_stack(t_stack **p_stack); | ||
void reverse_rotate_stack(t_stack **p_stack); | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* types.h :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/02/11 12:57:41 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/11 12:58:04 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef TYPES_H | ||
# define TYPES_H | ||
|
||
typedef t_list t_stack; | ||
|
||
typedef enum e_method | ||
{ | ||
INIT, | ||
FF, | ||
FR, | ||
RF, | ||
RR, | ||
} t_method; | ||
|
||
typedef struct s_content | ||
{ | ||
int index; | ||
int sf_cost; | ||
int sr_cost; | ||
int if_cost; | ||
int ir_cost; | ||
int min_cost; | ||
t_method opt_method; | ||
bool is_opt; | ||
} t_content; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* utils.h :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/02/11 12:39:00 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/11 12:39:47 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef UTILS_H | ||
# define UTILS_H | ||
|
||
# include "push_swap.h" | ||
|
||
void clear_stack(t_stack **p_stack, void (*del)(void *)); | ||
t_content *get_content(t_stack *st); | ||
int get_first_index(t_stack **p_stack); | ||
int get_second_index(t_stack **p_stack); | ||
int get_third_index(t_stack **p_stack); | ||
int stack_size(t_stack *stack); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,11 @@ | |
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/11 14:44:55 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/07 15:06:08 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/11 12:35:17 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "push_swap.h" | ||
#include "initialization.h" | ||
|
||
static bool _has_not_digit(int argc, char **argv) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,11 @@ | |
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/11 14:38:17 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/07 15:05:34 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/11 12:35:14 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "push_swap.h" | ||
#include "initialization.h" | ||
|
||
void exit_with_error(void) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,11 @@ | |
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/11 19:04:40 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/07 15:06:20 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/11 12:35:32 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "push_swap.h" | ||
#include "initialization.h" | ||
|
||
int *_generate_int_array(int array_size) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,13 @@ | |
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/10 12:37:36 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/10 21:19:08 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/11 12:54:10 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "initialization.h" | ||
#include "push_swap.h" | ||
#include "sort.h" | ||
|
||
#ifdef LEAK | ||
# ifdef __APPLE__ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,12 @@ | |
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/02/10 18:47:11 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/10 19:12:48 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/11 12:54:04 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "push_swap.h" | ||
#include "sort.h" | ||
|
||
bool is_sorted_stack(t_stack *st) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,13 @@ | |
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/02/10 10:43:16 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/10 20:34:46 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/11 12:53:46 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "large_sort.h" | ||
#include "push_swap.h" | ||
#include "stack_operations.h" | ||
|
||
static t_stack *_find_opt_st_b(t_stack **p_b) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,14 @@ | |
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/22 16:55:10 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/10 21:24:58 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/11 12:53:49 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "large_sort.h" | ||
#include "push_swap.h" | ||
#include "sort.h" | ||
#include "stack_operations.h" | ||
|
||
static void _push_b_n_times(t_stack **p_a, t_stack **p_b, int n) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,11 @@ | |
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/02/08 12:17:33 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/08 21:47:27 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/11 12:53:50 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "large_sort.h" | ||
#include "push_swap.h" | ||
|
||
static int _calc_insertion_threshold(t_stack **p_a, t_stack *st_b) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,11 @@ | |
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/02/09 10:23:28 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/10 21:08:19 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/11 12:53:55 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "large_sort.h" | ||
#include "push_swap.h" | ||
|
||
static int _calc_cost(t_stack *st_b, t_method method) | ||
|
Oops, something went wrong.