tgrekov-push_swap
HIVE push_swap July 2024
Loading...
Searching...
No Matches
sort.c File Reference

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sort.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/11 05:49:56 by tgrekov #+# #+# */
/* Updated: 2024/07/17 08:28:53 by tgrekov ### ########.fr */
/* */
/* ************************************************************************** */

Definition in file sort.c.

#include <stdlib.h>
#include "utils/utils.h"
#include "stack/stack.h"
Include dependency graph for sort.c:

Go to the source code of this file.

Functions

static int pick_i (t_stack *stack, int mode, int n)
 Find appropriate index for n in stack[mode]
 
static void rot_i (t_stack *stack, int mode, int i)
 Rotate to an index with rotate or reverse rotate, depending on which is shorter.
 
static int rot_cost (t_stack stack, int o_i, int o_len, int i)
 Determine move cost of rotating to an index, considering whether it is shorter to rotate or reverse rotate.
 
static void pick (t_stack *stack, int mode, int *costs)
 Determine which element to push from stack mode to the opposite stack by comparing their movement costs.
 
int sort (t_stack *stack)
 Output all instructions required to sort stack a.
 

Function Documentation

◆ pick()

static void pick ( t_stack stack,
int  mode,
int *  costs 
)
static

Determine which element to push from stack mode to the opposite stack by comparing their movement costs.

Parameters
[in,out]stack
[in]mode
[out]costs

Definition at line 114 of file sort.c.

References fallback(), get_minix(), pick_i(), r_rot(), rot(), rot_cost(), and rot_i().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pick_i()

static int pick_i ( t_stack stack,
int  mode,
int  n 
)
static

Find appropriate index for n in stack[mode]

Parameters
[in]stack
[in]mode
[in]n
Return values
int

Definition at line 32 of file sort.c.

References get_minix().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rot_cost()

static int rot_cost ( t_stack  stack,
int  o_i,
int  o_len,
int  i 
)
static

Determine move cost of rotating to an index, considering whether it is shorter to rotate or reverse rotate.

Parameters
[in]stack
[in]o_i
[in]o_len
[in]i
Return values
int

Definition at line 87 of file sort.c.

Here is the caller graph for this function:

◆ rot_i()

static void rot_i ( t_stack stack,
int  mode,
int  i 
)
static

Rotate to an index with rotate or reverse rotate, depending on which is shorter.

Parameters
[in,out]stack
[in]mode
[in]i

Definition at line 60 of file sort.c.

References r_rot(), and rot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sort()

int sort ( t_stack stack)

Output all instructions required to sort stack a.

Parameters
[in,out]stack
Return values
int

Definition at line 148 of file sort.c.

References err(), get_minix(), is_sorted(), pick(), push(), rot_i(), and swap().

Here is the call graph for this function: