Operations - pin3dev/42_PushSwap GitHub Wiki

swap

Swaps the top two elements of the stack:
This function exchanges the first two elements at the top of the stack. If the stack has fewer than two elements, no operation is performed.

Original Function:

Library None
Signature void swap(t_stack **stack);
Parameters stack: A pointer to the stack where the swap operation will be performed.
Return None

Usage Example:

// Initial stack: 5 -> 3 -> 8 -> NULL
swap(&stack_a); 
// After swap: 3 -> 5 -> 8 -> NULL

rotate

Rotates the stack by moving the top element to the bottom:
This function takes the top element of the stack and moves it to the bottom, effectively rotating the stack upwards.

Original Function:

Library None
Signature void rotate(t_stack **stack);
Parameters stack: A pointer to the stack to be rotated.
Return None

Usage Example:

// Initial stack: 5 -> 3 -> 8 -> NULL
rotate(&stack_a); 
// After rotate: 3 -> 8 -> 5 -> NULL

reverse_rotate

Reverse rotates the stack by moving the bottom element to the top:
This function takes the last element of the stack and moves it to the top, effectively rotating the stack downwards.

Original Function:

Library None
Signature void reverse_rotate(t_stack **stack);
Parameters stack: A pointer to the stack to be reverse rotated.
Return None

Usage Example:

// Initial stack: 5 -> 3 -> 8 -> NULL
reverse_rotate(&stack_a); 
// After reverse rotate: 8 -> 5 -> 3 -> NULL

push

Pushes the top element from the source stack to the destination stack:
This function removes the top element from the source stack and places it on the top of the destination stack.

Original Function:

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

Usage Example:

// Initial source stack (stack_b): 7 -> 9 -> NULL
// Initial destination stack (stack_a): 4 -> 2 -> 5 -> NULL
push(&stack_a, &stack_b); 
// After push:
// stack_a: 7 -> 4 -> 2 -> 5 -> NULL
// stack_b: 9 -> NULL

Previous ⬅️ Top ⬆️ Next ➡️

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