Skip to content

Commit

Permalink
working on operations
Browse files Browse the repository at this point in the history
  • Loading branch information
SaladBunda committed Apr 3, 2024
1 parent 3ae0322 commit 23c271e
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SRCS = main.c ft_split.c util_func1.c util_func2.c
SRCS = main.c ft_split.c util_func1.c util_func2.c operations.c
# SRCB =
DIR = ./srcs/
BONUS_DIR = ./bonus/
Expand Down
Binary file modified push_swap
Binary file not shown.
82 changes: 68 additions & 14 deletions srcs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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)
Expand All @@ -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)
{
Expand All @@ -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);
Expand Down
Binary file modified srcs/main.o
Binary file not shown.
33 changes: 33 additions & 0 deletions srcs/operations.c
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 added srcs/operations.o
Binary file not shown.
6 changes: 4 additions & 2 deletions srcs/push_swap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
/* */
/* ************************************************************************** */

Expand All @@ -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

0 comments on commit 23c271e

Please sign in to comment.