-
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
1 parent
3ae0322
commit 23c271e
Showing
7 changed files
with
106 additions
and
17 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
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,7 +6,7 @@ | |
/* By: ael-maaz <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/04/01 16:58:38 by ael-maaz #+# #+# */ | ||
/* Updated: 2024/04/03 02:00:53 by ael-maaz ### ########.fr */ | ||
/* Updated: 2024/04/03 02:54:25 by ael-maaz ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -35,7 +35,7 @@ void fill_stack(char **av, int ac, t_stack *stack_a) | |
{ | ||
int i = 0; | ||
int j ; | ||
int k = ; | ||
int k = stack_a->size - 1; | ||
stack_a->top = -1; | ||
char **arg; | ||
while(++i < ac) | ||
|
@@ -45,20 +45,36 @@ void fill_stack(char **av, int ac, t_stack *stack_a) | |
while(arg[++j]) | ||
{ | ||
stack_a->top++; | ||
stack_a->stack[k++] = ft_atoi(arg[j]); | ||
stack_a->stack[k--] = ft_atoi(arg[j]); | ||
} | ||
} | ||
int l = 0; | ||
while(l < stack_a->size) | ||
printf("%d\n",stack_a->stack[l++]); | ||
} | ||
|
||
void something(char **av, int ac, t_stack *stack_a) | ||
int duplicates(t_stack stack_a) | ||
{ | ||
// printf("ac = %d\n", ac); | ||
int i = 0; | ||
int j; | ||
char **arg; | ||
int i =0; | ||
int j =0; | ||
while(i < stack_a.size) | ||
{ | ||
j = 0; | ||
while(j < i) | ||
{ | ||
if(stack_a.stack[j] == stack_a.stack[i]) | ||
return 0; | ||
j++; | ||
} | ||
i++; | ||
} | ||
return 1; | ||
} | ||
|
||
void init_stacks(char **av, int ac, t_stack *stack_a, t_stack *stack_b) | ||
{ | ||
int i; | ||
int j; | ||
char **arg; | ||
|
||
i = 0; | ||
stack_a->size = 0; | ||
while(++i < ac) | ||
{ | ||
|
@@ -68,21 +84,59 @@ void something(char **av, int ac, t_stack *stack_a) | |
stack_a->size++; | ||
} | ||
stack_a->stack = malloc(sizeof(int) * stack_a->size); | ||
// printf("%d\n", stack_a->size); | ||
stack_b->size = stack_a->size; | ||
stack_b->stack = malloc(sizeof(int) * stack_b->size); | ||
stack_b->top = -1; | ||
fill_stack(av,ac,stack_a); | ||
return ; | ||
} | ||
|
||
void print_stacks(t_stack a,t_stack b) | ||
{ | ||
int i = 0; | ||
int j = 0; | ||
printf("-----------------stack a-----------\n"); | ||
while(i < a.top + 1) | ||
printf("%d\n", a.stack[i++]); | ||
printf("-----------------stack b------------\n"); | ||
while(j < b.top + 1) | ||
printf("%d\n", b.stack[j++]); | ||
} | ||
|
||
int main(int ac, char **av) | ||
{ | ||
t_stack a; | ||
// t_stack b; | ||
t_stack b; | ||
if (ac > 1) | ||
{ | ||
if(test_argv(av, ac) == 1) | ||
{ | ||
write(1, "valid\n", 6); | ||
something(av, ac, &a); | ||
init_stacks(av, ac, &a, &b); | ||
if(duplicates(a) == 0) | ||
return(write(1, "Error\n", 6),0); | ||
print_stacks(a,b); | ||
pb(&a,&b); | ||
print_stacks(a,b); | ||
pb(&a,&b); | ||
print_stacks(a,b); | ||
pb(&a,&b); | ||
print_stacks(a,b); | ||
pb(&a,&b); | ||
print_stacks(a,b); | ||
pb(&a,&b); | ||
print_stacks(a,b); | ||
printf("first part\n"); | ||
print_stacks(a,b); | ||
pa(&a,&b); | ||
print_stacks(a,b); | ||
pa(&a,&b); | ||
print_stacks(a,b); | ||
pa(&a,&b); | ||
print_stacks(a,b); | ||
pa(&a,&b); | ||
print_stacks(a,b); | ||
// printf("stack a top: %d stack b top: %d\n", a.stack[a.top],b.stack[b.top]); | ||
} | ||
else | ||
write(1, "Error\n", 6); | ||
|
Binary file not shown.
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,33 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* operations.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: ael-maaz <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/04/03 02:34:02 by ael-maaz #+# #+# */ | ||
/* Updated: 2024/04/03 02:44:08 by ael-maaz ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "push_swap.h" | ||
|
||
void pb(t_stack *a, t_stack *b) | ||
{ | ||
if(a->top > -1) | ||
{ | ||
b->top++; | ||
b->stack[b->top] = a->stack[a->top]; | ||
a->top--; | ||
} | ||
} | ||
|
||
void pa(t_stack *a, t_stack *b) | ||
{ | ||
if(b->top > -1) | ||
{ | ||
a->top++; | ||
a->stack[a->top] = b->stack[b->top]; | ||
b->top--; | ||
} | ||
} |
Binary file not shown.
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,7 +6,7 @@ | |
/* By: ael-maaz <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/04/01 16:59:48 by ael-maaz #+# #+# */ | ||
/* Updated: 2024/04/03 01:50:36 by ael-maaz ### ########.fr */ | ||
/* Updated: 2024/04/03 02:44:24 by ael-maaz ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -32,6 +32,8 @@ void *ft_memcpy(void *dst, const void *src, size_t n); | |
void ft_putstr(char *s); | ||
char **ft_split(char const *s, char c); | ||
void ft_putnbr(int n); | ||
int ft_atoi(const char *s); | ||
int ft_atoi(const char *s); | ||
void pb(t_stack *a, t_stack *b); | ||
void pa(t_stack *a, t_stack *b); | ||
|
||
#endif |