Markers - pin3dev/42_PushSwap GitHub Wiki

find_place_n_def_total_mov

Determines the right destination position for each node in the source stack and calculates the total movements required:
This function iterates through the source stack (src), finding the appropriate place in the destination stack (dest) for each node and calculates how many movements are necessary to move the node to that position in the destination stack.

Original Function:

Library None
Signature void find_place_n_def_total_mov(t_stack **src, t_stack **dest);
Parameters src: A pointer to the source stack, where each node will be evaluated and assigned a destination.
dest: A pointer to the destination stack, where the function will find the appropriate position.
Return None

Usage Example:

// Initial stack A (src): 4 -> 3 -> 5 -> NULL
// Initial stack B (dest): 1 -> 6 -> 9 -> NULL
find_place_n_def_total_mov(&stack_a, &stack_b);
// After execution, the optimal destination for each node in stack A is calculated:
// - Node 4 fits between 3 and 5.
// - Node 3 fits before node 6.
// - Node 5 fits between node 6 and node 9.
// Total movements for each node are also calculated by put_total_mov()

Specifics:

  • The function calls ck_new_min_max() to find the initial candidate for each node in src.
  • It then calculates the total movements required to move each node from src to its correct position in dest by calling put_total_mov().

put_index_n_def_mov_n_orient

Assigns index values and determines movement and orientation for nodes in both source and destination stacks:
This function assigns index values to nodes in both the source (src) and destination (dest) stacks. It calculates the required movements and orientations for each node to reach its destination.

Original Function:

Library None
Signature int put_index_n_def_mov_n_orient(t_stack **src, t_stack **dest);
Parameters src: A pointer to the source stack, where index values and movements will be assigned.
dest: A pointer to the destination stack, where index values and movements will also be assigned.
Return The number of elements in the source stack.

Usage Example:

// Initial stack A (src): 3 -> 5 -> 8 -> NULL
// Initial stack B (dest): 2 -> 7 -> 9 -> NULL
int size = put_index_n_def_mov_n_orient(&stack_a, &stack_b);
// After execution:
// - Stack A nodes receive sequential index values: 0 (3), 1 (5), 2 (8).
// - Stack B nodes receive sequential index values: 0 (2), 1 (7), 2 (9).
// - Movements and orientations are also determined for each node by put_mov_and_orientation()

Specifics:

  • Index values are assigned sequentially based on the node's position.
  • The function calculates how each node should be moved, using put_mov_and_orientation().

put_mov_and_orientation

Determines the number of movements and their orientation for each node in a stack:
This function calculates the number of moves (mov) and the movement orientation (mov_orientation) for each node in a stack, based on the node's index and the total size of the stack.

Original Function:

Library None
Signature void put_mov_and_orientation(int size, t_stack **stack);
Parameters size: The total number of nodes in the stack.
stack: A pointer to the stack, where movements and orientations will be assigned.
Return None

Usage Example:

// Initial stack: 3 -> 5 -> 8 -> 1 -> NULL
put_mov_and_orientation(4, &stack);
// After execution:
// - Node 3 (index 0) has mov=0, mov_orientation=0 (upwards).
// - Node 5 (index 1) has mov=1, mov_orientation=0 (upwards).
// - Node 8 (index 2) has mov=1, mov_orientation=1 (downwards).
// - Node 1 (index 3) has mov=0, mov_orientation=1 (downwards).

Specifics:

  • If a node’s index is in the first half of the stack, it moves upwards (mov_orientation = 0).
  • If a node’s index is in the second half of the stack, it moves downwards (mov_orientation = 1).
  • The mov field shows how many moves are needed to bring the node to the top of the stack.

put_total_mov

Calculates the total number of movements required to move a node from the source stack to its destination position:
This function computes the total number of moves (total_mov) required for a node in the source stack (src) to reach its correct position in the destination stack (dest).

Original Function:

Library None
Signature void put_total_mov(t_stack *src, t_stack *dest);
Parameters src: A pointer to the node in the source stack.
dest: A pointer to the node in the destination stack.
Return None

Usage Example:

// Source node: content = 5, mov = 2, mov_orientation = 0
// Destination node: content = 7, mov = 3, mov_orientation = 0
put_total_mov(src_node, dest_node);
// After execution, total_mov for node 5 is calculated as 3 (maximum of src->mov and dest->mov).

// If the destination node had mov_orientation = 1, the total_mov would be the sum of src->mov and dest->mov.

Specifics:

  • If the movement orientation of src and dest are the same, the total movement is set to the larger of src->mov and dest->mov.
  • If the orientations differ, the total movement is the sum of src->mov and dest->mov.

Previous ⬅️ Top ⬆️ Next ➡️

⚠️ **GitHub.com Fallback** ⚠️