mirror of
https://github.com/DavidGailleton/42-Push_Swap.git
synced 2026-01-27 16:51:57 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0712aa8c4 | ||
|
|
6b5347c997 | ||
|
|
89b7709d2d | ||
|
|
00af75f98f | ||
|
|
29c60fef6a | ||
| 60011b1b11 | |||
| f92eba4f03 | |||
| 1ebb32f58d | |||
| 52220b5b49 | |||
| 82111f59ad | |||
| f4824f2984 | |||
| 5ae963bb09 | |||
| 15ca9cfe3f |
31
.clang-format
Normal file
31
.clang-format
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
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
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -60,6 +60,7 @@ dkms.conf
|
|||||||
# Executable
|
# Executable
|
||||||
push_swap
|
push_swap
|
||||||
checker
|
checker
|
||||||
|
checker_linux
|
||||||
|
|
||||||
# File obj
|
# File obj
|
||||||
obj/
|
obj/
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -33,7 +33,7 @@ INSERTION = insertion.c
|
|||||||
FLAGS_FILES = algorithms_sort.c flag.c bench.c
|
FLAGS_FILES = algorithms_sort.c flag.c bench.c
|
||||||
|
|
||||||
PARSING = ft_atoi.c parsing.c ft_strncmp.c ft_split.c ft_strlen.c ft_substr.c ft_itoa.c ft_isdigit.c \
|
PARSING = ft_atoi.c parsing.c ft_strncmp.c ft_split.c ft_strlen.c ft_substr.c ft_itoa.c ft_isdigit.c \
|
||||||
ft_strjoin.c ft_strlcat.c ft_strlcpy.c parsing_2.c disorder.c
|
ft_strjoin.c ft_strlcat.c ft_strlcpy.c parsing_2.c disorder.c indexer.c
|
||||||
|
|
||||||
CHECKER_FILES = check_error.c verif_flag.c verif_is_digit.c verif_overflow.c verif_double.c
|
CHECKER_FILES = check_error.c verif_flag.c verif_is_digit.c verif_overflow.c verif_double.c
|
||||||
|
|
||||||
|
|||||||
79
README.md
79
README.md
@@ -1,5 +1,80 @@
|
|||||||
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 BUCKET SORT**
|
||||||
|
https://www.geeksforgeeks.org/dsa/radix-sort/
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
|||||||
@@ -12,17 +12,17 @@
|
|||||||
|
|
||||||
#include "push_swap.h"
|
#include "push_swap.h"
|
||||||
|
|
||||||
static int still_unit_value(t_stacks *stacks, int unit)
|
static int still_unit_index(t_stacks *stacks, int unit)
|
||||||
{
|
{
|
||||||
t_stack *temp;
|
t_stack *temp;
|
||||||
|
|
||||||
temp = stacks->a;
|
temp = stacks->a;
|
||||||
if (!temp || temp->value >= unit)
|
if (!temp || temp->index >= unit)
|
||||||
return (1);
|
return (1);
|
||||||
temp = temp->next;
|
temp = temp->next;
|
||||||
while (temp != stacks->a)
|
while (temp != stacks->a)
|
||||||
{
|
{
|
||||||
if (temp->value >= unit)
|
if (temp->index >= unit)
|
||||||
return (1);
|
return (1);
|
||||||
temp = temp->next;
|
temp = temp->next;
|
||||||
}
|
}
|
||||||
@@ -43,9 +43,9 @@ static void push_by_number_to_b(t_stacks *stacks, int unit, int nb)
|
|||||||
temp = temp->next;
|
temp = temp->next;
|
||||||
}
|
}
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < s_len && still_unit_value(stacks, unit))
|
while (i < s_len && still_unit_index(stacks, unit))
|
||||||
{
|
{
|
||||||
if (stacks->a && (stacks->a->value % (unit * 10)) / unit == nb)
|
if (stacks->a && (stacks->a->index % (unit * 10)) / unit == nb)
|
||||||
pb(stacks);
|
pb(stacks);
|
||||||
else
|
else
|
||||||
ra(stacks);
|
ra(stacks);
|
||||||
@@ -58,7 +58,7 @@ static void rec_sort(t_stacks *stacks, int unit)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if (!still_unit_value(stacks, unit))
|
if (!still_unit_index(stacks, unit))
|
||||||
return ;
|
return ;
|
||||||
while (i <= 9)
|
while (i <= 9)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,27 +18,27 @@
|
|||||||
|
|
||||||
static int apply_operation(t_stacks *stacks, char buf[1024])
|
static int apply_operation(t_stacks *stacks, char buf[1024])
|
||||||
{
|
{
|
||||||
if (!ft_strncmp("sa", buf, ft_strlen(buf)))
|
if (ft_strncmp("sa\n", buf, ft_strlen(buf)))
|
||||||
return (sa(stacks), 1);
|
return (sa(stacks), 1);
|
||||||
if (!ft_strncmp("sb", buf, ft_strlen(buf)))
|
if (ft_strncmp("sb\n", buf, ft_strlen(buf)))
|
||||||
return (sb(stacks), 1);
|
return (sb(stacks), 1);
|
||||||
if (!ft_strncmp("ss", buf, ft_strlen(buf)))
|
if (ft_strncmp("ss\n", buf, ft_strlen(buf)))
|
||||||
return (ss(stacks), 1);
|
return (ss(stacks), 1);
|
||||||
if (!ft_strncmp("pa", buf, ft_strlen(buf)))
|
if (ft_strncmp("pa\n", buf, ft_strlen(buf)))
|
||||||
return (pa(stacks), 1);
|
return (pa(stacks), 1);
|
||||||
if (!ft_strncmp("pb", buf, ft_strlen(buf)))
|
if (ft_strncmp("pb\n", buf, ft_strlen(buf)))
|
||||||
return (pb(stacks), 1);
|
return (pb(stacks), 1);
|
||||||
if (!ft_strncmp("ra", buf, ft_strlen(buf)))
|
if (ft_strncmp("ra\n", buf, ft_strlen(buf)))
|
||||||
return (ra(stacks), 1);
|
return (ra(stacks), 1);
|
||||||
if (!ft_strncmp("rb", buf, ft_strlen(buf)))
|
if (ft_strncmp("rb\n", buf, ft_strlen(buf)))
|
||||||
return (rb(stacks), 1);
|
return (rb(stacks), 1);
|
||||||
if (!ft_strncmp("rr", buf, ft_strlen(buf)))
|
if (ft_strncmp("rr\n", buf, ft_strlen(buf)))
|
||||||
return (rr(stacks), 1);
|
return (rr(stacks), 1);
|
||||||
if (!ft_strncmp("rra", buf, ft_strlen(buf)))
|
if (ft_strncmp("rra\n", buf, ft_strlen(buf)))
|
||||||
return (rra(stacks), 1);
|
return (rra(stacks), 1);
|
||||||
if (!ft_strncmp("rrb", buf, ft_strlen(buf)))
|
if (ft_strncmp("rrb\n", buf, ft_strlen(buf)))
|
||||||
return (rrb(stacks), 1);
|
return (rrb(stacks), 1);
|
||||||
if (!ft_strncmp("rrr", buf, ft_strlen(buf)))
|
if (ft_strncmp("rrr\n", buf, ft_strlen(buf)))
|
||||||
return (rrr(stacks), 1);
|
return (rrr(stacks), 1);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -63,10 +63,10 @@ static int tester(t_stacks *stacks)
|
|||||||
buf = get_next_line(0);
|
buf = get_next_line(0);
|
||||||
}
|
}
|
||||||
if (!is_stacks_b_empty(stacks))
|
if (!is_stacks_b_empty(stacks))
|
||||||
return (write(1, "KO\n", 3));
|
return (secure_write(1, "KO\n", 3));
|
||||||
if (!check_order(stacks->a))
|
if (!check_order(stacks->a))
|
||||||
return (write(1, "KO\n", 3));
|
return (secure_write(1, "KO\n", 3));
|
||||||
write(1, "OK\n", 3);
|
secure_write(1, "OK\n", 3);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ int main(int argc, char **argv)
|
|||||||
if (!tab)
|
if (!tab)
|
||||||
return (0);
|
return (0);
|
||||||
if (!check_error_bonus(tab))
|
if (!check_error_bonus(tab))
|
||||||
write(2, "Error\n", 7);
|
secure_write(2, "Error\n", 7);
|
||||||
else
|
else
|
||||||
bonus(tab);
|
bonus(tab);
|
||||||
free_tab(tab);
|
free_tab(tab);
|
||||||
|
|||||||
BIN
checker_linux
Executable file
BIN
checker_linux
Executable file
Binary file not shown.
@@ -19,7 +19,6 @@ void simple(t_stacks *stacks)
|
|||||||
int len;
|
int len;
|
||||||
|
|
||||||
len = stack_a_len(stacks);
|
len = stack_a_len(stacks);
|
||||||
stacks->algo = 1;
|
|
||||||
insertion(stacks, len);
|
insertion(stacks, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +28,6 @@ void medium(t_stacks *stacks)
|
|||||||
int range;
|
int range;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
stacks->algo = 2;
|
|
||||||
len = stack_a_len(stacks);
|
len = stack_a_len(stacks);
|
||||||
if (len == 2)
|
if (len == 2)
|
||||||
sort_two(stacks);
|
sort_two(stacks);
|
||||||
@@ -45,7 +43,6 @@ void medium(t_stacks *stacks)
|
|||||||
|
|
||||||
void complex(t_stacks *stacks)
|
void complex(t_stacks *stacks)
|
||||||
{
|
{
|
||||||
stacks->algo = 3;
|
|
||||||
radix(stacks);
|
radix(stacks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +52,7 @@ void adaptive(t_stacks *stacks, char **tab)
|
|||||||
float disorder;
|
float disorder;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
|
stacks->algo = 4;
|
||||||
while (!ft_isdigit(tab[i][0]) && tab[i])
|
while (!ft_isdigit(tab[i][0]) && tab[i])
|
||||||
i++;
|
i++;
|
||||||
disorder = stacks->disorder;
|
disorder = stacks->disorder;
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ static void print_disorder(t_stacks *stacks)
|
|||||||
secure_write(2, ".", 1);
|
secure_write(2, ".", 1);
|
||||||
if (ft_strlen(str) == 1)
|
if (ft_strlen(str) == 1)
|
||||||
secure_write(2, "0", 1);
|
secure_write(2, "0", 1);
|
||||||
secure_write(2, &str[ft_strlen(str) - 2], 2);
|
secure_write(2, &str[ft_strlen(str) - 2], ft_strlen(str) - 2);
|
||||||
secure_write(2, "%\n", 2);
|
secure_write(2, "%\n", 2);
|
||||||
free(str);
|
free(str);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,11 +62,20 @@ int pos_bench(char **argv, int mod)
|
|||||||
void flags(int pos, int pos_b, char **argv, t_stacks *stacks)
|
void flags(int pos, int pos_b, char **argv, t_stacks *stacks)
|
||||||
{
|
{
|
||||||
if (ft_strncmp(argv[pos], "--simple", 30) && pos > 0)
|
if (ft_strncmp(argv[pos], "--simple", 30) && pos > 0)
|
||||||
|
{
|
||||||
|
stacks->algo = 1;
|
||||||
simple(stacks);
|
simple(stacks);
|
||||||
|
}
|
||||||
else if (ft_strncmp(argv[pos], "--medium", 30) && pos > 0)
|
else if (ft_strncmp(argv[pos], "--medium", 30) && pos > 0)
|
||||||
|
{
|
||||||
|
stacks->algo = 2;
|
||||||
medium(stacks);
|
medium(stacks);
|
||||||
|
}
|
||||||
else if (ft_strncmp(argv[pos], "--complex", 30) && pos > 0)
|
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)
|
else if (ft_strncmp(argv[pos], "--adaptive", 30) && pos > 0)
|
||||||
adaptive(stacks, argv);
|
adaptive(stacks, argv);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -34,5 +34,6 @@ int ft_strlcat(char *dst, const char *src, int size);
|
|||||||
char *join_all(int argc, char **argv);
|
char *join_all(int argc, char **argv);
|
||||||
char **split_all(char *tab);
|
char **split_all(char *tab);
|
||||||
float compute_disorder(char **strs, int pos);
|
float compute_disorder(char **strs, int pos);
|
||||||
|
void indexer(t_stacks *stacks);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
typedef struct s_stack
|
typedef struct s_stack
|
||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
|
long long index;
|
||||||
struct s_stack *next;
|
struct s_stack *next;
|
||||||
struct s_stack *previous;
|
struct s_stack *previous;
|
||||||
} t_stack;
|
} t_stack;
|
||||||
|
|||||||
2
main.c
2
main.c
@@ -32,7 +32,7 @@ int main(int argc, char **argv)
|
|||||||
if (check_error(tab, mod))
|
if (check_error(tab, mod))
|
||||||
test1(tab, len, mod);
|
test1(tab, len, mod);
|
||||||
else
|
else
|
||||||
write(2, "Error\n", 7);
|
write(2, "Error\n", 6);
|
||||||
free_tab(tab);
|
free_tab(tab);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
54
parsing/indexer.c
Normal file
54
parsing/indexer.c
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* indexer.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/01/14 10:14:06 by dgaillet #+# #+# */
|
||||||
|
/* Updated: 2026/01/14 10:14:08 by dgaillet ### ########lyon.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "push_swap.h"
|
||||||
|
|
||||||
|
static t_stack *first_without_index(t_stack *stack)
|
||||||
|
{
|
||||||
|
t_stack *first;
|
||||||
|
|
||||||
|
if (stack->index < 0)
|
||||||
|
return (stack);
|
||||||
|
first = stack;
|
||||||
|
stack = stack->next;
|
||||||
|
while (stack != first)
|
||||||
|
{
|
||||||
|
if (stack->index < 0)
|
||||||
|
return (stack);
|
||||||
|
stack = stack->next;
|
||||||
|
}
|
||||||
|
return ((void *) 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void indexer(t_stacks *stacks)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int len;
|
||||||
|
t_stack *lower;
|
||||||
|
t_stack *temp;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
len = stack_a_len(stacks);
|
||||||
|
while (i < len)
|
||||||
|
{
|
||||||
|
lower = first_without_index(stacks->a);
|
||||||
|
temp = lower->next;
|
||||||
|
while (temp != stacks->a)
|
||||||
|
{
|
||||||
|
if (lower->value > temp->value && temp->index < 0)
|
||||||
|
lower = temp;
|
||||||
|
temp = temp->next;
|
||||||
|
}
|
||||||
|
lower->index = i;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/01/08 14:30:38 by dgaillet #+# #+# */
|
/* Created: 2026/01/08 14:30:38 by dgaillet #+# #+# */
|
||||||
/* Updated: 2026/01/09 12:05:56 by dgaillet ### ########lyon.fr */
|
/* Updated: 2026/01/09 14:55:16 by dgaillet ### ########lyon.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -17,6 +17,6 @@ void secure_write(int fd, char *str, int len)
|
|||||||
{
|
{
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
return ;
|
return ;
|
||||||
if (write(fd, str, len) < 0)
|
if (!str || write(fd, str, len) < 0)
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ void pa(t_stacks *stacks)
|
|||||||
stack_add_front(&(stacks->a), b_push);
|
stack_add_front(&(stacks->a), b_push);
|
||||||
stacks->pa++;
|
stacks->pa++;
|
||||||
if (stacks->print)
|
if (stacks->print)
|
||||||
write(1, "pa\n", 3);
|
secure_write(1, "pa\n", 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pb(t_stacks *stacks)
|
void pb(t_stacks *stacks)
|
||||||
@@ -53,5 +53,5 @@ void pb(t_stacks *stacks)
|
|||||||
stack_add_front(&(stacks->b), a_push);
|
stack_add_front(&(stacks->b), a_push);
|
||||||
stacks->pb++;
|
stacks->pb++;
|
||||||
if (stacks->print)
|
if (stacks->print)
|
||||||
write(1, "pb\n", 3);
|
secure_write(1, "pb\n", 3);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +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++;
|
||||||
write(1, "rra\n", 4);
|
secure_write(1, "rra\n", 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rrb(t_stacks *stacks)
|
void rrb(t_stacks *stacks)
|
||||||
@@ -27,7 +27,7 @@ void rrb(t_stacks *stacks)
|
|||||||
stacks->b = stacks->b->previous;
|
stacks->b = stacks->b->previous;
|
||||||
stacks->rrb++;
|
stacks->rrb++;
|
||||||
if (stacks->print)
|
if (stacks->print)
|
||||||
write(1, "rrb\n", 4);
|
secure_write(1, "rrb\n", 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rrr(t_stacks *stacks)
|
void rrr(t_stacks *stacks)
|
||||||
@@ -38,5 +38,5 @@ void rrr(t_stacks *stacks)
|
|||||||
stacks->a = stacks->a->previous;
|
stacks->a = stacks->a->previous;
|
||||||
stacks->rrr++;
|
stacks->rrr++;
|
||||||
if (stacks->print)
|
if (stacks->print)
|
||||||
write(1, "rrr\n", 4);
|
secure_write(1, "rrr\n", 4);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ void ra(t_stacks *stacks)
|
|||||||
stacks->a = stacks->a->next;
|
stacks->a = stacks->a->next;
|
||||||
stacks->ra++;
|
stacks->ra++;
|
||||||
if (stacks->print)
|
if (stacks->print)
|
||||||
write(1, "ra\n", 3);
|
secure_write(1, "ra\n", 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb(t_stacks *stacks)
|
void rb(t_stacks *stacks)
|
||||||
@@ -28,7 +28,7 @@ void rb(t_stacks *stacks)
|
|||||||
stacks->b = stacks->b->next;
|
stacks->b = stacks->b->next;
|
||||||
stacks->rb++;
|
stacks->rb++;
|
||||||
if (stacks->print)
|
if (stacks->print)
|
||||||
write(1, "rb\n", 3);
|
secure_write(1, "rb\n", 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rr(t_stacks *stacks)
|
void rr(t_stacks *stacks)
|
||||||
@@ -39,5 +39,5 @@ void rr(t_stacks *stacks)
|
|||||||
stacks->b = stacks->b->next;
|
stacks->b = stacks->b->next;
|
||||||
stacks->rr++;
|
stacks->rr++;
|
||||||
if (stacks->print)
|
if (stacks->print)
|
||||||
write(1, "rr\n", 3);
|
secure_write(1, "rr\n", 3);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ t_stack *new_stack(int value)
|
|||||||
if (!new)
|
if (!new)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
new->value = value;
|
new->value = value;
|
||||||
|
new->index = -1;
|
||||||
new->next = NULL;
|
new->next = NULL;
|
||||||
new->previous = NULL;
|
new->previous = NULL;
|
||||||
return (new);
|
return (new);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ void sa(t_stacks *stacks)
|
|||||||
a->next->value = stock;
|
a->next->value = stock;
|
||||||
stacks->sa++;
|
stacks->sa++;
|
||||||
if (stacks->print)
|
if (stacks->print)
|
||||||
write(1, "sa\n", 3);
|
secure_write(1, "sa\n", 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sb(t_stacks *stacks)
|
void sb(t_stacks *stacks)
|
||||||
@@ -42,7 +42,7 @@ void sb(t_stacks *stacks)
|
|||||||
b->next->value = stock;
|
b->next->value = stock;
|
||||||
stacks->sb++;
|
stacks->sb++;
|
||||||
if (stacks->print)
|
if (stacks->print)
|
||||||
write(1, "sb\n", 3);
|
secure_write(1, "sb\n", 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ss(t_stacks *stacks)
|
void ss(t_stacks *stacks)
|
||||||
@@ -69,5 +69,5 @@ void ss(t_stacks *stacks)
|
|||||||
}
|
}
|
||||||
stacks->ss++;
|
stacks->ss++;
|
||||||
if (stacks->print)
|
if (stacks->print)
|
||||||
write(1, "ss\n", 3);
|
secure_write(1, "ss\n", 3);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ int test1(char **tab, int len, int mod)
|
|||||||
if (mod == -1)
|
if (mod == -1)
|
||||||
return (0);
|
return (0);
|
||||||
stacks = init_stacks(len, tab, mod);
|
stacks = init_stacks(len, tab, mod);
|
||||||
|
indexer(stacks);
|
||||||
if (!stacks)
|
if (!stacks)
|
||||||
return (0);
|
return (0);
|
||||||
if (check_order(stacks->a))
|
if (check_order(stacks->a))
|
||||||
|
|||||||
Reference in New Issue
Block a user