Stack Operations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Arrays and Data-Structures > STK. - Stack > STK.Operations >

Stack Operations

STK.Rotate

Previous Next

 


MiniRobotLanguage (MRL)

 

STK.Rotate|$$STK[|$$ANZ]

Rotate the top $$ANZ elements on the stack.

 

Intention

The STK.Rotate command moves the top $$ANZ elements of the stack, rotating them such that the top element becomes the bottom of the selected elements, and the second element becomes the top. This operation effectively shifts elements circularly within the specified range.

If $$ANZ is omitted or set to 0, all elements on the stack are rotated.

 

 

Syntax

 

STK.Rotate|$$STK[|$$ANZ]

 

Parameter Explanation

 

P1 - $$STK: The stack handle whose elements are to be rotated.

P2 - $$ANZ (Optional): The number of elements to rotate from the top of the stack. If omitted or set to 0, all elements on the stack are rotated.

 

Example

 

'***********************************

' Example 1: Rotate Top 3 Elements

'***********************************

STK.New|$$STK

STK.Push|$$STK|1

STK.Push|$$STK|2

STK.Push|$$STK|3

STK.Push|$$STK|4

STK.Rotate|$$STK|3

STK.Pop|$$STK|$$RES

JIV.$$RES!2|Lab_Failed

STK.End|$$STK

ENR.

 

'***********************************

' Example 2: Rotate All Elements

'***********************************

STK.New|$$STK

STK.Push|$$STK|A

STK.Push|$$STK|B

STK.Push|$$STK|C

STK.Rotate|$$STK

STK.Pop|$$STK|$$RES

JIS.$$RES!A|Lab_Failed

STK.End|$$STK

ENR.

 

 

 

Remarks

- Rotations are performed in a circular manner. Elements moved off the top are placed at the bottom of the selected range.

- If $$ANZ is greater than the number of elements in the stack, the command defaults to rotating all elements.

 

Limitations:

- The stack handle must be valid before calling STK.Rotate. Invalid handles will result in an error.

 

See also:

STK.New

STK.End