|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Arrays and Data-Structures > STK. - Stack > STK.Operations > Stack Operations |
MiniRobotLanguage (MRL)
STK.Swapx|$$STK[|$$ELA][|$$ELB]
Swap multiple elements on the stack with extended functionality.
Intention
The STK.Swapx command swaps the elements at positions $$ELA and $$ELB on the stack. This provides extended functionality for rearranging stack elements.
If $$ELA is omitted, it defaults to 1 (Top of Stack). If $$ELB is omitted, it defaults to the last element (Bottom of Stack).
Syntax
STK.Swapx|$$STK[|$$ELA][|$$ELB]
Parameter Explanation
P1 - $$STK: The stack handle where the elements are to be swapped.
P2 - $$ELA (Optional): The position of the first element to swap. Defaults to 1 (Top of Stack) if omitted.
P3 - $$ELB (Optional): The position of the second element to swap. Defaults to the last element (Bottom of Stack) if omitted.
Example
'***********************************
' Example 1: Swap Top and Bottom
'***********************************
STK.New|$$STK
STK.Push|$$STK|First
STK.Push|$$STK|Second
STK.Push|$$STK|Third
STK.Swapx|$$STK
STK.Pop|$$STK|$$RES
JIS.$$RES!First|Lab_Failed
STK.End|$$STK
ENR.
'***********************************
' Example 2: Swap Specific Elements
'***********************************
STK.New|$$STK
STK.Push|$$STK|10
STK.Push|$$STK|20
STK.Push|$$STK|30
STK.Swapx|$$STK|1|2
STK.Pop|$$STK|$$RES
JIV.$$RES!10|Lab_Failed
STK.Pop|$$STK|$$RES
JIV.$$RES!30|Lab_Failed
STK.End|$$STK
ENR.
Remarks
- Ensure the specified positions ($$ELA and $$ELB) are within the bounds of the stack.
Limitations:
- The stack handle must be valid before calling STK.Swapx. Invalid handles will result in an error.
See also:
• STK.Swap
• STK.New