​push_swap /
src / cli / init_stacks.c
162 commits
02-05-2026
30 lines 1.2 kB
 1/* ************************************************************************** */
 2/*                                                                            */
 3/*                                                        :::      ::::::::   */
 4/*   init_stacks.c                                      :+:      :+:    :+:   */
 5/*                                                    +:+ +:+         +:+     */
 6/*   By: mleitao <marvin@42.fr>                     +#+  +:+       +#+        */
 7/*                                                +#+#+#+#+#+   +#+           */
 8/*   Created: 2026/04/29 18:59:54 by mleitao           #+#    #+#             */
 9/*   Updated: 2026/05/02 15:43:15 by mleitao          ###   ########.fr       */
10/*                                                                            */
11/* ************************************************************************** */
12
13#include "cli.h"
14#include "stack.h"
15#include <stdlib.h>
16
17void	init_stacks(t_stack *a, t_stack *b, int *values, int capacity)
18{
19	if (stack_build(a, values, capacity) == -1)
20	{
21		free(values);
22		die(ERR_MALLOC);
23	}
24	free(values);
25	if (stack_init(b, a->capacity) == -1)
26	{
27		stack_free(a);
28		die(ERR_MALLOC);
29	}
30}