|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Arrays and Data-Structures > ARS. - Array's > ARS. - Deque Operations |
📘 SPR Deque Operations Manual
This guide provides a comprehensive overview of Deque operations in SPR, explaining what they are, how to use them, and why they are a powerful tool for scripting. Whether you're a beginner or an experienced user, this manual will help you master Deque operations with clear explanations and practical examples. Let’s dive in! 🚀
•What is a Deque?
•Deque Commands Overview
•Code Examples
A **Deque** (double-ended queue) in SPR is a generalization of a queue and a stack where elements can be added or removed from both the front and the back. This makes it a highly versatile data structure for various applications.
Deques are useful for scenarios where you need the flexibility of adding and removing elements from both ends, such as implementing sliding windows, palindrome checks, and more.
Here’s a quick overview of the most common Deque commands:
ARS.PeekFirst|$$ARS|$$RES: Peek at the first element of the Deque.
ARS.PeekLast|$$ARS|$$RES: Peek at the last element of the Deque.
ARS.PopFirst|$$ARS|$$RES: Pop the first element from the Deque.
ARS.PopLast|$$ARS|$$RES: Pop the last element from the Deque.
ARS.PushFirst|$$ARS|Value: Push an element onto the front of the Deque.
ARS.PushLast|$$ARS|Value: Push an element onto the end of the Deque.
Example: Using Deque Operations
' Create a Deque
ARS.New|$$DEQUE
' Add items to the Deque
ARS.PushFirst|$$DEQ|Apple
ARS.PushLast|$$DEQ|Banana
ARS.PushLast|$$DEQ|Cherry
' Peek at the first and last elements
ARS.PeekFirst|$$DEQ|$$FIR
MBX. First: $$FIR ' Output: Apple
ARS.PeekLast|$$DEQ|$$LAS
MBX. Last: $$LAS ' Output: Cherry
' Pop the first and last elements
ARS.PopFirst|$$DEQUE|$$RES
MBX. Popped: $$RES ' Output: Apple
ARS.PopLast|$$DEQUE|$$RES
MBX. Popped: $$RES ' Output: Cherry
' Free the Deque
ARS.End|$$DEQUE