mirror of
https://github.com/DavidGailleton/42-Push_Swap.git
synced 2026-01-27 08:41:58 +00:00
Compare commits
29 Commits
error_valg
...
e947183aab
| Author | SHA1 | Date | |
|---|---|---|---|
| e947183aab | |||
|
|
52e1ef8947 | ||
|
|
b2652cacc7 | ||
|
|
ae1a91c7c9 | ||
| 798886976c | |||
| e2cbea4df9 | |||
| 88b7525bac | |||
|
|
3887e3b4a5 | ||
|
|
a3a462a515 | ||
|
|
587ea1750c | ||
|
|
afa8785379 | ||
| 0e7d1dce50 | |||
|
|
469320374d | ||
| ddd5b11a7a | |||
|
|
854d699780 | ||
|
|
52d868904f | ||
|
|
81ed92dc88 | ||
|
|
c6f04ab48f | ||
|
|
e266b6d6e9 | ||
|
|
59a80e6c9b | ||
| e9c0894f92 | |||
|
|
381bd66c2b | ||
| c2e7da01f4 | |||
|
|
75c331e7ea | ||
| 78ec8a3fa4 | |||
|
|
c323449e3a | ||
|
|
e0712aa8c4 | ||
| 2c805c9506 | |||
|
|
6b5347c997 |
@@ -1,31 +0,0 @@
|
|||||||
Language: C
|
|
||||||
|
|
||||||
AlignConsecutiveDeclarations: false
|
|
||||||
AlignConsecutiveMacros: false
|
|
||||||
AlignEscapedNewlinesLeft: true
|
|
||||||
AllowAllParametersOfDeclarationOnNextLine: false
|
|
||||||
AllowShortBlocksOnASingleLine: false
|
|
||||||
AllowShortFunctionsOnASingleLine: None
|
|
||||||
AlwaysBreakAfterReturnType: None
|
|
||||||
AlwaysBreakBeforeMultilineStrings: false
|
|
||||||
BinPackArguments: true
|
|
||||||
BinPackParameters: true
|
|
||||||
BreakBeforeBraces: Allman
|
|
||||||
BreakBeforeTernaryOperators: false
|
|
||||||
ColumnLimit: 80
|
|
||||||
IndentWidth: 4
|
|
||||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
|
||||||
MaxEmptyLinesToKeep: 1
|
|
||||||
PointerAlignment: Right
|
|
||||||
PenaltyBreakBeforeFirstCallParameter: 1
|
|
||||||
PenaltyBreakString: 1
|
|
||||||
PenaltyExcessCharacter: 0
|
|
||||||
SpaceAfterCStyleCast: true
|
|
||||||
SpaceBeforeAssignmentOperators: true
|
|
||||||
SpaceBeforeParens: ControlStatements
|
|
||||||
SpaceInEmptyParentheses: false
|
|
||||||
SpacesInCStyleCastParentheses: false
|
|
||||||
SpacesInParentheses: false
|
|
||||||
SpacesInSquareBrackets: false
|
|
||||||
TabWidth: 4
|
|
||||||
UseTab: Always
|
|
||||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -60,6 +60,10 @@ dkms.conf
|
|||||||
# Executable
|
# Executable
|
||||||
push_swap
|
push_swap
|
||||||
checker
|
checker
|
||||||
|
checker_linux
|
||||||
|
|
||||||
# File obj
|
# File obj
|
||||||
obj/
|
obj/
|
||||||
|
|
||||||
|
#playtest
|
||||||
|
playtest.sh
|
||||||
|
|||||||
9
Makefile
9
Makefile
@@ -26,7 +26,7 @@ INCLUDES = includes
|
|||||||
# ALL FILES WITHOUT PATH
|
# ALL FILES WITHOUT PATH
|
||||||
#============================
|
#============================
|
||||||
|
|
||||||
SRC = main.c test_one.c ft_putnbr.c secure_write.c
|
SRC = main.c ft_putnbr.c secure_write.c
|
||||||
|
|
||||||
INSERTION = insertion.c
|
INSERTION = insertion.c
|
||||||
|
|
||||||
@@ -39,7 +39,8 @@ CHECKER_FILES = check_error.c verif_flag.c verif_is_digit.c verif_overflow.c ver
|
|||||||
|
|
||||||
STACK_UTILS = push.c rev_rotate.c rotate.c stack_add.c stack_remove.c stacks_len.c swap.c
|
STACK_UTILS = push.c rev_rotate.c rotate.c stack_add.c stack_remove.c stacks_len.c swap.c
|
||||||
|
|
||||||
MEDIUM_ALGO = utils_medium.c utils_struct_tab.c utils_medium_two.c sort_utils.c sort_utils_two.c medium_algo.c
|
MEDIUM_ALGO = utils_medium.c utils_struct_tab.c utils_medium_two.c sort_utils.c sort_utils_two.c medium_algo.c \
|
||||||
|
move_patha.c move_pathb.c
|
||||||
|
|
||||||
COMPLEX_ALGO = radix.c
|
COMPLEX_ALGO = radix.c
|
||||||
|
|
||||||
@@ -58,7 +59,7 @@ OBJ_DIR = obj
|
|||||||
|
|
||||||
CC = cc
|
CC = cc
|
||||||
|
|
||||||
CFLAGS = -Wall -Werror -Wextra -g3 -I$(INCLUDES)
|
CFLAGS = -Wall -Werror -Wextra -I$(INCLUDES)
|
||||||
|
|
||||||
NAME = push_swap
|
NAME = push_swap
|
||||||
|
|
||||||
@@ -104,7 +105,7 @@ $(NAME): $(OBJ)
|
|||||||
$(NAME_BONUS): $(BONUS_OBJ)
|
$(NAME_BONUS): $(BONUS_OBJ)
|
||||||
@$(CC) $(CFLAGS) $(BONUS_OBJ) -o $(NAME_BONUS)
|
@$(CC) $(CFLAGS) $(BONUS_OBJ) -o $(NAME_BONUS)
|
||||||
@echo "===================================="
|
@echo "===================================="
|
||||||
@echo "======= PUSH SWAP COMPILED ========="
|
@echo "======= CHECKER COMPILED ==========="
|
||||||
@echo "===================================="
|
@echo "===================================="
|
||||||
|
|
||||||
$(OBJ_DIR)/%.o: $(PARS_DIR)/%.c | $(OBJ_DIR)
|
$(OBJ_DIR)/%.o: $(PARS_DIR)/%.c | $(OBJ_DIR)
|
||||||
|
|||||||
83
README.md
83
README.md
@@ -1,5 +1,84 @@
|
|||||||
This project has been created as part of the 42 curriculum by mteriier[, dgaillet].
|
*This project has been created as part of the 42 curriculum by dgaillet[, mteriier].*
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
|
|
||||||
The *Push swap* project goal is to sort values with push swap operations beetween 2 stack (*a* and *b*)
|
The **Push swap** project goal is to sort values with push swap operations beetween 2 stack (*a* and *b*)
|
||||||
|
with different algorithms. Depends on the difficulties to solve the stacks. We will select a certain algorithms.
|
||||||
|
|
||||||
|
The difficulty is calculate with a disorder function *(compute_disorder)*. Disorder result will be between 0 and 1.
|
||||||
|
|
||||||
|
Selected algo depends on the disorder:
|
||||||
|
|
||||||
|
**Disorder < 0.2 ( O(n2) ):**
|
||||||
|
- Insertion sort adaptation ( len = 500 > complexity = 30 000)
|
||||||
|
|
||||||
|
**0.2 >= Disorder < 0.5 ( O(n√n) ):**
|
||||||
|
- Bucket sort adaptations with √n buckets ( len = 500 > complexity = 11900)
|
||||||
|
|
||||||
|
**Disorder >= 0.5 ( O(n log n) ):**
|
||||||
|
- Radix sort adaptation (LSD or MSD) ( len = 500 > complexity = 8000)
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
|
||||||
|
### 1. Command to compile push_swap :
|
||||||
|
```
|
||||||
|
make
|
||||||
|
```
|
||||||
|
### 2. Command to compile bonus :
|
||||||
|
|
||||||
|
```
|
||||||
|
make bonus
|
||||||
|
```
|
||||||
|
### 3. Command to delete all objects and exec :
|
||||||
|
|
||||||
|
```
|
||||||
|
make fclean
|
||||||
|
```
|
||||||
|
### 3. Command exemples how to use push_swap :
|
||||||
|
|
||||||
|
```
|
||||||
|
./push_swap 7 5 8 12 30 -20
|
||||||
|
```
|
||||||
|
```
|
||||||
|
ARG="7 5 8 12 30 -20"; ./push_swap $ARG
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. Command exemples how to use checker :
|
||||||
|
|
||||||
|
```
|
||||||
|
./checker 7 5 8 12 30 -20
|
||||||
|
(put the command like pa,ra,rr,rrr ...)
|
||||||
|
```
|
||||||
|
### 5. Command exemples how to use checker and push_swap together :
|
||||||
|
|
||||||
|
```
|
||||||
|
ARG="7 5 8 12 30 -20"; ./push_swap $ARG | ./checker $ARG
|
||||||
|
```
|
||||||
|
|
||||||
|
## Resources
|
||||||
|
|
||||||
|
- **For the algorithms**
|
||||||
|
https://en.wikipedia.org/wiki/Sorting_algorithm
|
||||||
|
|
||||||
|
- **For BUCKET SORT**
|
||||||
|
https://www.meilisearch.com/blog/bucket-sort-guide
|
||||||
|
|
||||||
|
- **For RADIX**
|
||||||
|
https://www.geeksforgeeks.org/dsa/radix-sort/
|
||||||
|
|
||||||
|
### AI
|
||||||
|
|
||||||
|
AI was utilized to provide a reminder on how to include obj files within a subfolder for the Makefile.
|
||||||
|
|
||||||
|
## Additional sections may be required depending on the project
|
||||||
|
|
||||||
|
### Justification to why we chose this algorithms
|
||||||
|
- **Insertion sort**
|
||||||
|
We select **Insertion** cause that was the more simple to implement with the restrictions.
|
||||||
|
|
||||||
|
- **Bucket sort**
|
||||||
|
We select **Bucket** cause i like how the algorithms sort.
|
||||||
|
Define the range and the number of buckets.
|
||||||
|
|
||||||
|
- **Radix sort**
|
||||||
|
We select **Radix** cause that was the more simple to implement with the restrictions.
|
||||||
|
|||||||
@@ -14,67 +14,6 @@
|
|||||||
#include "medium_headers.h"
|
#include "medium_headers.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
static int path_to_end(t_stacks *stacks, int max_range, int range, char c)
|
|
||||||
{
|
|
||||||
t_stack *tmp;
|
|
||||||
int i;
|
|
||||||
int first_pass;
|
|
||||||
|
|
||||||
if (c == 'a')
|
|
||||||
tmp = stacks->a;
|
|
||||||
else
|
|
||||||
tmp = stacks->b;
|
|
||||||
tmp = tmp->previous;
|
|
||||||
i = 0;
|
|
||||||
first_pass = 1;
|
|
||||||
while (first_pass || tmp != stacks->b->previous)
|
|
||||||
{
|
|
||||||
first_pass = 0;
|
|
||||||
if (in_range(tmp->value, max_range, range))
|
|
||||||
tmp = stacks->b;
|
|
||||||
tmp = tmp->previous;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int path_to_start(t_stacks *stacks, int max_range, int range, char c)
|
|
||||||
{
|
|
||||||
t_stack *tmp;
|
|
||||||
int i;
|
|
||||||
int first_pass;
|
|
||||||
|
|
||||||
if (c == 'a')
|
|
||||||
tmp = stacks->a;
|
|
||||||
else
|
|
||||||
tmp = stacks->b;
|
|
||||||
i = 0;
|
|
||||||
first_pass = 1;
|
|
||||||
while (first_pass || tmp != stacks->b)
|
|
||||||
{
|
|
||||||
first_pass = 0;
|
|
||||||
if (in_range(tmp->value, max_range, range))
|
|
||||||
{
|
|
||||||
tmp = stacks->b->previous;
|
|
||||||
}
|
|
||||||
tmp = tmp->next;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
||||||
int wich_path(t_stacks *stacks, int max_range, int range, char c)
|
|
||||||
{
|
|
||||||
int path_start;
|
|
||||||
int path_end;
|
|
||||||
|
|
||||||
path_start = path_to_start(stacks, max_range, range, c);
|
|
||||||
path_end = path_to_end(stacks, max_range, range, c);
|
|
||||||
if (path_start < path_end)
|
|
||||||
return (1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int stack_len(t_stack *stack)
|
int stack_len(t_stack *stack)
|
||||||
{
|
{
|
||||||
t_stack *first;
|
t_stack *first;
|
||||||
@@ -108,7 +47,5 @@ void bucket_algo(t_stacks *stacks, t_tab *preset, int range)
|
|||||||
free(preset);
|
free(preset);
|
||||||
preset = tmp;
|
preset = tmp;
|
||||||
}
|
}
|
||||||
while (stacks->b)
|
|
||||||
pa(stacks);
|
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|||||||
94
algorithms/medium/move_patha.c
Normal file
94
algorithms/medium/move_patha.c
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* move_patha.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/01/16 06:20:47 by mteriier #+# #+# */
|
||||||
|
/* Updated: 2026/01/16 06:20:55 by mteriier ### ########lyon.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "medium_headers.h"
|
||||||
|
#include "push_swap.h"
|
||||||
|
|
||||||
|
static int is_border_a(int value, t_stacks *stacks)
|
||||||
|
{
|
||||||
|
t_stack *tmp;
|
||||||
|
|
||||||
|
if (!stacks->a)
|
||||||
|
return (1);
|
||||||
|
tmp = assign_stack(stacks, 'a');
|
||||||
|
if ((value < tmp->index && check_order(tmp))
|
||||||
|
|| (value > tmp->index && value > tmp->previous->index
|
||||||
|
&& check_order(stacks->a)))
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int move_left_to_right(int value, t_stacks *stacks, int is_move)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
t_stack *tmp;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
tmp = assign_stack(stacks, 'a');
|
||||||
|
while (value > tmp->index && !is_move)
|
||||||
|
{
|
||||||
|
tmp = tmp->next;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
while (value > stacks->a->index && is_move)
|
||||||
|
ra(stacks);
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int move_right_to_left(int value, t_stacks *stacks, int is_move)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
t_stack *tmp;
|
||||||
|
|
||||||
|
tmp = assign_stack(stacks, 'a');
|
||||||
|
i = 0;
|
||||||
|
while (value < tmp->previous->index && !is_move)
|
||||||
|
{
|
||||||
|
tmp = tmp->previous;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
while (value < stacks->a->previous->index && is_move)
|
||||||
|
rra(stacks);
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int wich_path_a(int value, t_stacks *stacks)
|
||||||
|
{
|
||||||
|
t_stack *tmp;
|
||||||
|
int move_from_left;
|
||||||
|
int move_from_right;
|
||||||
|
|
||||||
|
tmp = assign_stack(stacks, 'a');
|
||||||
|
if (is_border_a(value, stacks))
|
||||||
|
return (-1);
|
||||||
|
move_from_left = move_left_to_right(value, stacks, 0);
|
||||||
|
move_from_right = move_right_to_left(value, stacks, 0);
|
||||||
|
if ((check_order(stacks->a) && move_from_left < move_from_right)
|
||||||
|
|| (move_from_left > move_from_right && !check_order(stacks->a)))
|
||||||
|
return (1);
|
||||||
|
else
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void move_ra_rra(int value, t_stacks *stacks)
|
||||||
|
{
|
||||||
|
if (is_border_a(value, stacks))
|
||||||
|
return ;
|
||||||
|
if (wich_path_a(value, stacks) == 1)
|
||||||
|
{
|
||||||
|
move_left_to_right(value, stacks, 1);
|
||||||
|
}
|
||||||
|
else if (wich_path_a(value, stacks) == 0)
|
||||||
|
{
|
||||||
|
move_right_to_left(value, stacks, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
115
algorithms/medium/move_pathb.c
Normal file
115
algorithms/medium/move_pathb.c
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* move_pathb.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/01/16 06:20:38 by mteriier #+# #+# */
|
||||||
|
/* Updated: 2026/01/16 06:20:42 by mteriier ### ########lyon.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "medium_headers.h"
|
||||||
|
#include "push_swap.h"
|
||||||
|
|
||||||
|
static int path_to_end(t_stacks *stacks, int max_range, int range, char c)
|
||||||
|
{
|
||||||
|
t_stack *tmp;
|
||||||
|
t_stack *start;
|
||||||
|
int i;
|
||||||
|
int first_pass;
|
||||||
|
|
||||||
|
tmp = assign_stack(stacks, c);
|
||||||
|
start = assign_stack(stacks, c);
|
||||||
|
tmp = tmp->previous;
|
||||||
|
i = 0;
|
||||||
|
first_pass = 1;
|
||||||
|
while (first_pass || tmp != start->previous)
|
||||||
|
{
|
||||||
|
first_pass = 0;
|
||||||
|
if (in_range(tmp->index, max_range, range))
|
||||||
|
tmp = start;
|
||||||
|
tmp = tmp->previous;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int path_to_start(t_stacks *stacks, int max_range, int range, char c)
|
||||||
|
{
|
||||||
|
t_stack *tmp;
|
||||||
|
t_stack *start;
|
||||||
|
int i;
|
||||||
|
int first_pass;
|
||||||
|
|
||||||
|
tmp = assign_stack(stacks, c);
|
||||||
|
start = assign_stack(stacks, c);
|
||||||
|
i = 0;
|
||||||
|
first_pass = 1;
|
||||||
|
while (first_pass || tmp != start)
|
||||||
|
{
|
||||||
|
first_pass = 0;
|
||||||
|
if (in_range(tmp->index, max_range, range))
|
||||||
|
{
|
||||||
|
tmp = start->previous;
|
||||||
|
}
|
||||||
|
tmp = tmp->next;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int wich_path(t_stacks *stacks, int max_range, int range, char c)
|
||||||
|
{
|
||||||
|
int path_start;
|
||||||
|
int path_end;
|
||||||
|
|
||||||
|
path_start = path_to_start(stacks, max_range, range, c);
|
||||||
|
path_end = path_to_end(stacks, max_range, range, c);
|
||||||
|
if (path_start < path_end)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void normal_move_path(t_stacks *stacks, t_tab *one_preset, int range)
|
||||||
|
{
|
||||||
|
if (wich_path(stacks, one_preset->max_range, range, 'b'))
|
||||||
|
{
|
||||||
|
while (!in_range(stacks->b->index, one_preset->max_range, range))
|
||||||
|
rb(stacks);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (!in_range(stacks->b->index, one_preset->max_range, range))
|
||||||
|
{
|
||||||
|
rrb(stacks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_pre_move_b(t_stacks *stacks, t_tab *one_preset, int range)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
t_stack *tmp;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
tmp = assign_stack(stacks, 'b');
|
||||||
|
if (wich_path(stacks, one_preset->max_range, range, 'b'))
|
||||||
|
{
|
||||||
|
while (!in_range(tmp->index, one_preset->max_range, range))
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
tmp = tmp->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (!in_range(tmp->index, one_preset->max_range, range))
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
tmp = tmp->previous;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
@@ -13,83 +13,79 @@
|
|||||||
#include "push_swap.h"
|
#include "push_swap.h"
|
||||||
#include "medium_headers.h"
|
#include "medium_headers.h"
|
||||||
|
|
||||||
static int number_move_reverse(t_stacks *stacks, int value, char start_end)
|
void move_rr_rrr(t_stacks *stacks, int move, char c)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
t_stack *tmp;
|
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
tmp = stacks->a;
|
while (i < move && c == 's')
|
||||||
if (start_end == 's')
|
|
||||||
{
|
{
|
||||||
while (tmp->value < value)
|
rr(stacks);
|
||||||
{
|
|
||||||
tmp = tmp->next;
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
while (i < move && c == 'e')
|
||||||
else
|
|
||||||
{
|
{
|
||||||
tmp = tmp->previous;
|
|
||||||
while (tmp->value > value)
|
|
||||||
{
|
|
||||||
tmp = tmp->previous;
|
|
||||||
i++;
|
i++;
|
||||||
|
rrr(stacks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int sort_path(t_stacks *stacks, int value)
|
void put_in_order_ra_rra(t_stacks *stacks)
|
||||||
{
|
{
|
||||||
int start_path;
|
int i;
|
||||||
int end_path;
|
|
||||||
|
|
||||||
start_path = number_move_reverse(stacks, value, 's');
|
i = 0;
|
||||||
if (start_path == 0)
|
while (!check_order(stacks->a) && i < 50)
|
||||||
return (1);
|
|
||||||
end_path = number_move_reverse(stacks, value, 'e');
|
|
||||||
if (start_path < end_path)
|
|
||||||
return (1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void sort_little_pile(t_stacks *stacks)
|
|
||||||
{
|
{
|
||||||
if (!stacks->a)
|
|
||||||
{
|
|
||||||
pa(stacks);
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
if (stacks->a->previous->value < stacks->b->value)
|
|
||||||
{
|
|
||||||
pa(stacks);
|
|
||||||
ra(stacks);
|
ra(stacks);
|
||||||
return ;
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void path_rr_rrr(int value, t_stacks *stacks, t_tab *one_preset, int range)
|
||||||
|
{
|
||||||
|
int move_a;
|
||||||
|
int final_move;
|
||||||
|
|
||||||
|
final_move = get_pre_move_b(stacks, one_preset, range);
|
||||||
|
if (wich_path_a(value, stacks) == 1
|
||||||
|
&& wich_path(stacks, one_preset->max_range, range, 'b'))
|
||||||
|
{
|
||||||
|
move_a = move_left_to_right(value, stacks, 0);
|
||||||
|
if (move_a < final_move)
|
||||||
|
final_move = move_a;
|
||||||
|
move_rr_rrr(stacks, final_move, 's');
|
||||||
|
}
|
||||||
|
else if (wich_path_a(value, stacks) == 0
|
||||||
|
&& !wich_path(stacks, one_preset->max_range, range, 'b'))
|
||||||
|
{
|
||||||
|
move_a = move_right_to_left(value, stacks, 0);
|
||||||
|
if (move_a < final_move)
|
||||||
|
final_move = move_a;
|
||||||
|
move_rr_rrr(stacks, final_move, 'e');
|
||||||
}
|
}
|
||||||
if (sort_path(stacks, stacks->b->value))
|
|
||||||
sort_from_left(stacks);
|
|
||||||
else
|
|
||||||
sort_from_right(stacks);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void push_range_to_b(t_stacks *stacks, t_tab *one_preset, int range)
|
void push_range_to_b(t_stacks *stacks, t_tab *one_preset, int range)
|
||||||
{
|
{
|
||||||
|
int value;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
while (one_preset->nb_in > 0)
|
while (one_preset->nb_in > 0)
|
||||||
{
|
{
|
||||||
if (wich_path(stacks, one_preset->max_range, range, 'b'))
|
if (stacks->a)
|
||||||
{
|
{
|
||||||
while (!in_range(stacks->b->value, one_preset->max_range, range))
|
value = get_value_finded(stacks, one_preset, range);
|
||||||
rb(stacks);
|
path_rr_rrr(value, stacks, one_preset, range);
|
||||||
}
|
}
|
||||||
else
|
normal_move_path(stacks, one_preset, range);
|
||||||
{
|
move_ra_rra(stacks->b->index, stacks);
|
||||||
while (!in_range(stacks->b->value, one_preset->max_range, range))
|
pa(stacks);
|
||||||
{
|
put_in_order_ra_rra(stacks);
|
||||||
rrb(stacks);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sort_little_pile(stacks);
|
|
||||||
one_preset->nb_in--;
|
one_preset->nb_in--;
|
||||||
|
i++;
|
||||||
|
if (!check_order(stacks->a))
|
||||||
|
return ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,39 +11,33 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "push_swap.h"
|
#include "push_swap.h"
|
||||||
|
#include "medium_headers.h"
|
||||||
|
|
||||||
void sort_from_left(t_stacks *stacks)
|
int get_value_finded(t_stacks *stacks, t_tab *one_preset, int range)
|
||||||
{
|
{
|
||||||
int i;
|
int value;
|
||||||
|
t_stack *tmp;
|
||||||
|
|
||||||
i = 0;
|
tmp = assign_stack(stacks, 'b');
|
||||||
while (stacks->b->value > stacks->a->value)
|
if (wich_path(stacks, one_preset->max_range, range, 'b'))
|
||||||
{
|
{
|
||||||
ra(stacks);
|
while (!in_range(tmp->index, one_preset->max_range, range))
|
||||||
i++;
|
tmp = tmp->next;
|
||||||
}
|
|
||||||
pa(stacks);
|
|
||||||
while (i > 0)
|
|
||||||
{
|
|
||||||
rra(stacks);
|
|
||||||
i--;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
while (!in_range(tmp->index, one_preset->max_range, range))
|
||||||
|
tmp = tmp->previous;
|
||||||
|
value = tmp->index;
|
||||||
|
return (value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sort_from_right(t_stacks *stacks)
|
t_stack *assign_stack(t_stacks *stacks, char c)
|
||||||
{
|
{
|
||||||
int i;
|
t_stack *tmp;
|
||||||
|
|
||||||
i = 0;
|
if (c == 'a')
|
||||||
while (stacks->b->value < stacks->a->previous->value)
|
tmp = stacks->a;
|
||||||
{
|
else
|
||||||
rra(stacks);
|
tmp = stacks->b;
|
||||||
i++;
|
return (tmp);
|
||||||
}
|
|
||||||
pa(stacks);
|
|
||||||
while (i >= 0)
|
|
||||||
{
|
|
||||||
ra(stacks);
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ int get_first_lower(t_stack *first)
|
|||||||
int pass;
|
int pass;
|
||||||
|
|
||||||
tmp = first;
|
tmp = first;
|
||||||
lower = tmp->value;
|
lower = tmp->index;
|
||||||
pass = 1;
|
pass = 1;
|
||||||
while (tmp != first || pass == 1)
|
while (tmp != first || pass == 1)
|
||||||
{
|
{
|
||||||
pass = 0;
|
pass = 0;
|
||||||
if (lower > tmp->value)
|
if (lower > tmp->index)
|
||||||
lower = tmp->value;
|
lower = tmp->index;
|
||||||
tmp = tmp->next;
|
tmp = tmp->next;
|
||||||
}
|
}
|
||||||
return (lower);
|
return (lower);
|
||||||
@@ -43,9 +43,9 @@ int get_next_lower(t_stack *first, int old_lower)
|
|||||||
while (tmp != first || skip_first)
|
while (tmp != first || skip_first)
|
||||||
{
|
{
|
||||||
skip_first = 0;
|
skip_first = 0;
|
||||||
if (old_lower < tmp->value && tmp->value <= next_lower)
|
if (old_lower < tmp->index && tmp->index <= next_lower)
|
||||||
{
|
{
|
||||||
next_lower = tmp->value;
|
next_lower = tmp->index;
|
||||||
if (next_lower == -2147483648)
|
if (next_lower == -2147483648)
|
||||||
return (next_lower);
|
return (next_lower);
|
||||||
}
|
}
|
||||||
@@ -96,7 +96,7 @@ int get_number_in_range(int max_range, t_stack *a, int range)
|
|||||||
while (tmp != first || pass == 1)
|
while (tmp != first || pass == 1)
|
||||||
{
|
{
|
||||||
pass = 0;
|
pass = 0;
|
||||||
if (in_range(tmp->value, max_range, range))
|
if (in_range(tmp->index, max_range, range))
|
||||||
nb_in++;
|
nb_in++;
|
||||||
tmp = tmp->next;
|
tmp = tmp->next;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,13 +20,13 @@ static int get_max_number(t_stack *first)
|
|||||||
t_stack *a;
|
t_stack *a;
|
||||||
|
|
||||||
a = first;
|
a = first;
|
||||||
max = a->value;
|
max = a->index;
|
||||||
pass = 1;
|
pass = 1;
|
||||||
while (a != first || pass == 1)
|
while (a != first || pass == 1)
|
||||||
{
|
{
|
||||||
pass = 0;
|
pass = 0;
|
||||||
if (max < a->value)
|
if (max < a->index)
|
||||||
max = a->value;
|
max = a->index;
|
||||||
a = a->next;
|
a = a->next;
|
||||||
}
|
}
|
||||||
return (max);
|
return (max);
|
||||||
@@ -39,13 +39,13 @@ static int get_min_number(t_stack *first)
|
|||||||
int pass;
|
int pass;
|
||||||
|
|
||||||
a = first;
|
a = first;
|
||||||
min = a->value;
|
min = a->index;
|
||||||
pass = 1;
|
pass = 1;
|
||||||
while (a != first || pass == 1)
|
while (a != first || pass == 1)
|
||||||
{
|
{
|
||||||
pass = 0;
|
pass = 0;
|
||||||
if (min > a->value)
|
if (min > a->index)
|
||||||
min = a->value;
|
min = a->index;
|
||||||
a = a->next;
|
a = a->next;
|
||||||
}
|
}
|
||||||
return (min);
|
return (min);
|
||||||
|
|||||||
@@ -33,15 +33,8 @@ static void push_by_number_to_b(t_stacks *stacks, int unit, int nb)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int s_len;
|
int s_len;
|
||||||
t_stack *temp;
|
|
||||||
|
|
||||||
temp = stacks->a;
|
s_len = stack_a_len(stacks);
|
||||||
s_len = 1;
|
|
||||||
while (temp && temp->next != stacks->a)
|
|
||||||
{
|
|
||||||
s_len++;
|
|
||||||
temp = temp->next;
|
|
||||||
}
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < s_len && still_unit_index(stacks, unit))
|
while (i < s_len && still_unit_index(stacks, unit))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -58,14 +58,18 @@ static int tester(t_stacks *stacks)
|
|||||||
while (buf)
|
while (buf)
|
||||||
{
|
{
|
||||||
if (!apply_operation(stacks, buf))
|
if (!apply_operation(stacks, buf))
|
||||||
break ;
|
{
|
||||||
|
secure_write(2, "Error\n", 6);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
free(buf);
|
free(buf);
|
||||||
buf = get_next_line(0);
|
buf = get_next_line(0);
|
||||||
}
|
}
|
||||||
if (!is_stacks_b_empty(stacks))
|
if (!is_stacks_b_empty(stacks) || !check_order(stacks->a))
|
||||||
return (secure_write(1, "KO\n", 3));
|
{
|
||||||
if (!check_order(stacks->a))
|
secure_write(1, "KO\n", 3);
|
||||||
return (secure_write(1, "KO\n", 3));
|
return (0);
|
||||||
|
}
|
||||||
secure_write(1, "OK\n", 3);
|
secure_write(1, "OK\n", 3);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,16 @@ static int is_exist_flag(char **tab, int pos)
|
|||||||
return (verif);
|
return (verif);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int is_algo_flag(char *str)
|
||||||
|
{
|
||||||
|
if (ft_strncmp(str, "--simple", 30)
|
||||||
|
|| ft_strncmp(str, "--medium", 30)
|
||||||
|
|| ft_strncmp(str, "--adaptive", 30)
|
||||||
|
|| ft_strncmp(str, "--complex", 30))
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
static int verif_exist_flag(char **tab, int mod)
|
static int verif_exist_flag(char **tab, int mod)
|
||||||
{
|
{
|
||||||
int verif;
|
int verif;
|
||||||
@@ -37,6 +47,8 @@ static int verif_exist_flag(char **tab, int mod)
|
|||||||
{
|
{
|
||||||
if (is_exist_flag(tab, 1) && is_exist_flag(tab, 2))
|
if (is_exist_flag(tab, 1) && is_exist_flag(tab, 2))
|
||||||
verif = 1;
|
verif = 1;
|
||||||
|
if (is_algo_flag(tab[1]) && is_algo_flag(tab[2]))
|
||||||
|
verif = 0;
|
||||||
}
|
}
|
||||||
return (verif);
|
return (verif);
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
checker_linux
BIN
checker_linux
Binary file not shown.
@@ -46,21 +46,15 @@ void complex(t_stacks *stacks)
|
|||||||
radix(stacks);
|
radix(stacks);
|
||||||
}
|
}
|
||||||
|
|
||||||
void adaptive(t_stacks *stacks, char **tab)
|
void adaptive(t_stacks *stacks)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
float disorder;
|
float disorder;
|
||||||
|
|
||||||
i = 0;
|
|
||||||
stacks->algo = 4;
|
|
||||||
while (!ft_isdigit(tab[i][0]) && tab[i])
|
|
||||||
i++;
|
|
||||||
disorder = stacks->disorder;
|
disorder = stacks->disorder;
|
||||||
if (disorder < 0.3)
|
if (disorder < 0.2)
|
||||||
simple(stacks);
|
simple(stacks);
|
||||||
else if (disorder < 0.5)
|
else if (disorder < 0.5)
|
||||||
medium(stacks);
|
medium(stacks);
|
||||||
else
|
else
|
||||||
complex(stacks);
|
complex(stacks);
|
||||||
return ;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ static void print_disorder(t_stacks *stacks)
|
|||||||
int nbr;
|
int nbr;
|
||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
nbr = (int) stacks->disorder * 10000;
|
stacks->disorder *= 10000;
|
||||||
|
nbr = (int) stacks->disorder;
|
||||||
str = ft_itoa(nbr);
|
str = ft_itoa(nbr);
|
||||||
if (!str)
|
if (!str)
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
@@ -33,6 +34,7 @@ static void print_disorder(t_stacks *stacks)
|
|||||||
secure_write(2, "0", 1);
|
secure_write(2, "0", 1);
|
||||||
secure_write(2, &str[ft_strlen(str) - 2], ft_strlen(str) - 2);
|
secure_write(2, &str[ft_strlen(str) - 2], ft_strlen(str) - 2);
|
||||||
secure_write(2, "%\n", 2);
|
secure_write(2, "%\n", 2);
|
||||||
|
stacks->disorder /= 10000;
|
||||||
free(str);
|
free(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,20 +43,20 @@ static void print_algo(t_stacks *stacks)
|
|||||||
secure_write(2, "[bench] algo: ", 14);
|
secure_write(2, "[bench] algo: ", 14);
|
||||||
if (stacks->algo == 0)
|
if (stacks->algo == 0)
|
||||||
{
|
{
|
||||||
secure_write(2, "Adaptative", 10);
|
secure_write(2, "Adaptive", 8);
|
||||||
if (stacks->disorder < 0.2)
|
if (stacks->disorder < 0.2)
|
||||||
secure_write(2, " / O(n2n)\n", 10);
|
secure_write(2, " / O(n2n)\n", 10);
|
||||||
else if (stacks->disorder >= 0.5)
|
else if (stacks->disorder >= 0.5)
|
||||||
secure_write(2, " / O(n√n)\n", 10);
|
|
||||||
else
|
|
||||||
secure_write(2, " / O(nlogn)\n", 12);
|
secure_write(2, " / O(nlogn)\n", 12);
|
||||||
|
else
|
||||||
|
secure_write(2, " / O(n√n)\n", 12);
|
||||||
}
|
}
|
||||||
else if (stacks->algo == 1)
|
else if (stacks->algo == 1)
|
||||||
secure_write(2, "Simple / O(n2n)\n", 16);
|
secure_write(2, "Simple / O(n2n)\n", 16);
|
||||||
else if (stacks->algo == 2)
|
else if (stacks->algo == 2)
|
||||||
secure_write(2, "Medium / O(nlogn)\n", 18);
|
secure_write(2, "Medium / O(n√n)\n", 18);
|
||||||
else if (stacks->algo == 3)
|
else if (stacks->algo == 3)
|
||||||
secure_write(2, "Complex / O(n√n)\n", 17);
|
secure_write(2, "Complex / O(nlogn)\n", 19);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_total_ops(t_stacks *stacks)
|
static void print_total_ops(t_stacks *stacks)
|
||||||
|
|||||||
60
flags/flag.c
60
flags/flag.c
@@ -19,67 +19,21 @@ int calcul_mod(int argc, char **argv)
|
|||||||
int mod;
|
int mod;
|
||||||
|
|
||||||
mod = 0;
|
mod = 0;
|
||||||
while (argv[mod] && !ft_isdigit(argv[mod][0]) && mod < argc)
|
while (argv[mod] && !ft_isdigit(argv[mod][0])
|
||||||
|
&& !ft_isdigit(argv[mod][1]) && argv[mod][1] && mod < argc)
|
||||||
mod++;
|
mod++;
|
||||||
mod--;
|
mod--;
|
||||||
return (mod);
|
return (mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
int pos_flag(char **argv, int mod)
|
void flags(t_stacks *stacks)
|
||||||
{
|
{
|
||||||
if (mod == 1 || mod == 4)
|
if (stacks->algo == 1)
|
||||||
{
|
|
||||||
if (!ft_strncmp(argv[1], "--bench", 20))
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
else if (mod == 2 || mod == 5)
|
|
||||||
{
|
|
||||||
if (!ft_strncmp(argv[1], "--bench", 20))
|
|
||||||
return (1);
|
|
||||||
else
|
|
||||||
return (2);
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int pos_bench(char **argv, int mod)
|
|
||||||
{
|
|
||||||
if (mod == 1 || mod == 4)
|
|
||||||
{
|
|
||||||
if (ft_strncmp(argv[1], "--bench", 20))
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
else if (mod == 2 || mod == 5)
|
|
||||||
{
|
|
||||||
if (ft_strncmp(argv[1], "--bench", 20))
|
|
||||||
return (1);
|
|
||||||
else
|
|
||||||
return (2);
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void flags(int pos, int pos_b, char **argv, t_stacks *stacks)
|
|
||||||
{
|
|
||||||
if (ft_strncmp(argv[pos], "--simple", 30) && pos > 0)
|
|
||||||
{
|
|
||||||
stacks->algo = 1;
|
|
||||||
simple(stacks);
|
simple(stacks);
|
||||||
}
|
if (stacks->algo == 1)
|
||||||
else if (ft_strncmp(argv[pos], "--medium", 30) && pos > 0)
|
|
||||||
{
|
|
||||||
stacks->algo = 2;
|
|
||||||
medium(stacks);
|
medium(stacks);
|
||||||
}
|
if (stacks->algo == 1)
|
||||||
else if (ft_strncmp(argv[pos], "--complex", 30) && pos > 0)
|
|
||||||
{
|
|
||||||
stacks->algo = 3;
|
|
||||||
complex(stacks);
|
complex(stacks);
|
||||||
}
|
|
||||||
else if (ft_strncmp(argv[pos], "--adaptive", 30) && pos > 0)
|
|
||||||
adaptive(stacks, argv);
|
|
||||||
else
|
else
|
||||||
adaptive(stacks, argv);
|
adaptive(stacks);
|
||||||
if (pos_b > 0)
|
|
||||||
stacks->bench = 1;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ static void rec_ft_putnbr_fd(int nbr, int fd)
|
|||||||
|
|
||||||
if (!nbr)
|
if (!nbr)
|
||||||
return ;
|
return ;
|
||||||
ft_putnbr_fd(nbr / 10, fd);
|
rec_ft_putnbr_fd(nbr / 10, fd);
|
||||||
c = (nbr % 10) + '0';
|
c = (nbr % 10) + '0';
|
||||||
secure_write(fd, &c, 1);
|
secure_write(fd, &c, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,8 @@
|
|||||||
void simple(t_stacks *stacks);
|
void simple(t_stacks *stacks);
|
||||||
void medium(t_stacks *stacks);
|
void medium(t_stacks *stacks);
|
||||||
void complex(t_stacks *stacks);
|
void complex(t_stacks *stacks);
|
||||||
void adaptive(t_stacks *stacks, char **tab);
|
void adaptive(t_stacks *stacks);
|
||||||
void flags(int pos, int pos_b, char **argv, t_stacks *stacks);
|
void flags(t_stacks *stacks);
|
||||||
int pos_bench(char **argv, int mod);
|
|
||||||
int pos_flag(char **argv, int mod);
|
|
||||||
int calcul_mod(int argc, char **argv);
|
int calcul_mod(int argc, char **argv);
|
||||||
void print_bench(t_stacks *stacks);
|
void print_bench(t_stacks *stacks);
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
#ifndef MEDIUM_HEADERS_H
|
#ifndef MEDIUM_HEADERS_H
|
||||||
# define MEDIUM_HEADERS_H
|
# define MEDIUM_HEADERS_H
|
||||||
|
|
||||||
|
# include "push_swap.h"
|
||||||
|
|
||||||
typedef struct s_tab
|
typedef struct s_tab
|
||||||
{
|
{
|
||||||
int max_range;
|
int max_range;
|
||||||
@@ -25,9 +27,10 @@ int wich_path(t_stacks *stacks, int max_range, int range, char c);
|
|||||||
int stack_len(t_stack *stack);
|
int stack_len(t_stack *stack);
|
||||||
void bucket_algo(t_stacks *stacks, t_tab *preset, int range);
|
void bucket_algo(t_stacks *stacks, t_tab *preset, int range);
|
||||||
/* SORT UTILS FILES */
|
/* SORT UTILS FILES */
|
||||||
void sort_from_left(t_stacks *stacks);
|
|
||||||
void sort_from_right(t_stacks *stacks);
|
|
||||||
void push_range_to_b(t_stacks *stacks, t_tab *one_preset, int range);
|
void push_range_to_b(t_stacks *stacks, t_tab *one_preset, int range);
|
||||||
|
void normal_move_path(t_stacks *stacks, t_tab *one_preset, int range);
|
||||||
|
t_stack *assign_stack(t_stacks *stacks, char c);
|
||||||
|
int get_value_finded(t_stacks *stacks, t_tab *one_preset, int range);
|
||||||
/* MEDIUM UTILS FILES */
|
/* MEDIUM UTILS FILES */
|
||||||
int range_bucket(t_stack *first);
|
int range_bucket(t_stack *first);
|
||||||
int get_first_lower(t_stack *first);
|
int get_first_lower(t_stack *first);
|
||||||
@@ -37,5 +40,13 @@ int in_range(int value, int max_range, int range);
|
|||||||
int get_number_in_range(int max_range, t_stack *a, int range);
|
int get_number_in_range(int max_range, t_stack *a, int range);
|
||||||
/* UTILS STRUCT TAB FILE */
|
/* UTILS STRUCT TAB FILE */
|
||||||
t_tab *get_tabs(t_stack *first, int range);
|
t_tab *get_tabs(t_stack *first, int range);
|
||||||
|
/* MOVE PATH FILES*/
|
||||||
|
int get_pre_move_b(t_stacks *stacks, t_tab *one_preset, int range);
|
||||||
|
int move_left_to_right(int value, t_stacks *stacks, int is_move);
|
||||||
|
int move_right_to_left(int value, t_stacks *stacks, int is_move);
|
||||||
|
int wich_path_a(int value, t_stacks *stacks);
|
||||||
|
void move_ra_rra(int value, t_stacks *stacks);
|
||||||
|
void path_rr_rrr(int value, t_stacks *stacks, t_tab *one_preset, int range);
|
||||||
|
void put_in_order_ra_rra(t_stacks *stacks);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
21
main.c
21
main.c
@@ -16,6 +16,25 @@
|
|||||||
#include "flags.h"
|
#include "flags.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
static int push_swap(char **tab, int len, int mod)
|
||||||
|
{
|
||||||
|
t_stacks *stacks;
|
||||||
|
|
||||||
|
stacks = NULL;
|
||||||
|
if (mod == -1)
|
||||||
|
return (0);
|
||||||
|
stacks = init_stacks(len, tab, mod);
|
||||||
|
if (!stacks)
|
||||||
|
return (0);
|
||||||
|
indexer(stacks);
|
||||||
|
if (!check_order(stacks->a))
|
||||||
|
flags(stacks);
|
||||||
|
if (stacks->bench == 1)
|
||||||
|
print_bench(stacks);
|
||||||
|
free_all(stacks);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char **tab;
|
char **tab;
|
||||||
@@ -30,7 +49,7 @@ int main(int argc, char **argv)
|
|||||||
len = len_split(tab);
|
len = len_split(tab);
|
||||||
mod = calcul_mod(len, tab);
|
mod = calcul_mod(len, tab);
|
||||||
if (check_error(tab, mod))
|
if (check_error(tab, mod))
|
||||||
test1(tab, len, mod);
|
push_swap(tab, len, mod);
|
||||||
else
|
else
|
||||||
write(2, "Error\n", 6);
|
write(2, "Error\n", 6);
|
||||||
free_tab(tab);
|
free_tab(tab);
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* checker.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2026/01/08 12:37:12 by dgaillet #+# #+# */
|
|
||||||
/* Updated: 2026/01/08 13:17:36 by dgaillet ### ########lyon.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "push_swap.h"
|
|
||||||
#include "parsing.h"
|
|
||||||
|
|
||||||
static int check_digits(char *str)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (str[i])
|
|
||||||
{
|
|
||||||
if (!ft_isdigit(str[i]) && str[i] != ' ')
|
|
||||||
return (0);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int check_flags(char *str)
|
|
||||||
{
|
|
||||||
if (!ft_strncmp("--simple", str, ft_strlen(str)))
|
|
||||||
return (1);
|
|
||||||
else if (!ft_strncmp("--medium", str, ft_strlen(str)))
|
|
||||||
return (1);
|
|
||||||
else if (!ft_strncmp("--complex", str, ft_strlen(str)))
|
|
||||||
return (1);
|
|
||||||
else if (!ft_strncmp("--adaptative", str, ft_strlen(str)))
|
|
||||||
return (1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int checker(int argc, char **argv)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int methods_flag;
|
|
||||||
int bench;
|
|
||||||
|
|
||||||
bench = 0;
|
|
||||||
methods_flag = 0;
|
|
||||||
i = 0;
|
|
||||||
while (++i < argc)
|
|
||||||
{
|
|
||||||
if (check_flags(argv[1]) && !methods_flag)
|
|
||||||
methods_flag = 1;
|
|
||||||
else if (!ft_strncmp("--bench", argv[1], ft_strlen(argv[1])) && !bench)
|
|
||||||
bench = 1;
|
|
||||||
else if (check_digits(argv[1]))
|
|
||||||
continue ;
|
|
||||||
else
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
@@ -65,6 +65,25 @@ static void set_t_stacks(t_stacks *stacks)
|
|||||||
stacks->rrr = 0;
|
stacks->rrr = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void set_flags(int argc, char **argv, t_stacks *stacks)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 1;
|
||||||
|
while (i < argc)
|
||||||
|
{
|
||||||
|
if (ft_strncmp(argv[i], "--simple", ft_strlen(argv[i])))
|
||||||
|
stacks->algo = 1;
|
||||||
|
else if (ft_strncmp(argv[i], "--medium", ft_strlen(argv[i])))
|
||||||
|
stacks->algo = 2;
|
||||||
|
else if (ft_strncmp(argv[i], "--complex", ft_strlen(argv[i])))
|
||||||
|
stacks->algo = 3;
|
||||||
|
if (ft_strncmp(argv[i], "--bench", ft_strlen(argv[i])))
|
||||||
|
stacks->bench = 1;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
t_stacks *init_stacks(int argc, char **argv, int mod)
|
t_stacks *init_stacks(int argc, char **argv, int mod)
|
||||||
{
|
{
|
||||||
t_stacks *stacks;
|
t_stacks *stacks;
|
||||||
@@ -81,5 +100,7 @@ t_stacks *init_stacks(int argc, char **argv, int mod)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
stacks->a = a;
|
stacks->a = a;
|
||||||
|
set_flags(argc, argv, stacks);
|
||||||
|
stacks->disorder = compute_disorder(argv, wich_mod(mod));
|
||||||
return (stacks);
|
return (stacks);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ void rra(t_stacks *stacks)
|
|||||||
if (stacks && stacks->a && stacks->a->previous)
|
if (stacks && stacks->a && stacks->a->previous)
|
||||||
stacks->a = stacks->a->previous;
|
stacks->a = stacks->a->previous;
|
||||||
stacks->rra++;
|
stacks->rra++;
|
||||||
|
if (stacks->print)
|
||||||
secure_write(1, "rra\n", 4);
|
secure_write(1, "rra\n", 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
40
test_one.c
40
test_one.c
@@ -1,40 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* test_one.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: mteriier <mteriier@student.lyon42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2025/12/22 12:33:58 by mteriier #+# #+# */
|
|
||||||
/* Updated: 2026/01/08 15:35:43 by dgaillet ### ########lyon.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "push_swap.h"
|
|
||||||
#include "flags.h"
|
|
||||||
#include "parsing.h"
|
|
||||||
#include "medium_headers.h"
|
|
||||||
|
|
||||||
int test1(char **tab, int len, int mod)
|
|
||||||
{
|
|
||||||
t_stacks *stacks;
|
|
||||||
|
|
||||||
stacks = NULL;
|
|
||||||
if (mod == -1)
|
|
||||||
return (0);
|
|
||||||
stacks = init_stacks(len, tab, mod);
|
|
||||||
indexer(stacks);
|
|
||||||
if (!stacks)
|
|
||||||
return (0);
|
|
||||||
if (check_order(stacks->a))
|
|
||||||
{
|
|
||||||
free_all(stacks);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
stacks->disorder = compute_disorder(tab, wich_mod(mod));
|
|
||||||
flags(pos_flag(tab, mod), pos_bench(tab, mod), tab, stacks);
|
|
||||||
if (stacks->bench == 1)
|
|
||||||
print_bench(stacks);
|
|
||||||
free_all(stacks);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user