​push_swap /
src / push_swap.c
162 commits
04-05-2026
52 lines 1.7 kB
 1/* ************************************************************************** */
 2/*                                                                            */
 3/*                                                        :::      ::::::::   */
 4/*   push_swap.c                                        :+:      :+:    :+:   */
 5/*                                                    +:+ +:+         +:+     */
 6/*   By: ohaponiu <marvin@42.fr>                    +#+  +:+       +#+        */
 7/*                                                +#+#+#+#+#+   +#+           */
 8/*   Created: 2026/04/20 17:15:43 by ohaponiu          #+#    #+#             */
 9/*   Updated: 2026/05/04 12:49:02 by ohaponiu         ###   ########.fr       */
10/*                                                                            */
11/* ************************************************************************** */
12
13#include "cli.h"
14#include "metrics.h"
15#include "stack.h"
16#include "strategies.h"
17#include <libft.h>
18
19static int	*get_values(int argc, char **argv, t_flags *flags, int *capacity)
20{
21	int	first_arg;
22
23	first_arg = parse_flags(flags, argc, argv);
24	if (first_arg >= argc)
25		return (NULL);
26	return (parse_args(argc - first_arg, argv + first_arg, capacity));
27}
28
29static void	solve(t_context *ctx)
30{
31	ft_bzero(&ctx->ops, sizeof(t_ops));
32	ctx->disorder = disorder(&ctx->a);
33	dispatch(ctx);
34	if (ctx->flags.bench)
35		bench(ctx);
36	stack_free(&ctx->a);
37	stack_free(&ctx->b);
38}
39
40int	main(int argc, char **argv)
41{
42	t_context	ctx;
43	int			*values;
44	int			capacity;
45
46	values = get_values(argc, argv, &ctx.flags, &capacity);
47	if (!values)
48		return (0);
49	init_stacks(&ctx.a, &ctx.b, values, capacity);
50	solve(&ctx);
51	return (0);
52}