
- Rexx 教程
- Rexx - 首頁
- Rexx - 概述
- Rexx - 環境
- Rexx - 安裝
- Rexx - 外掛安裝
- Rexx - 基本語法
- Rexx - 資料型別
- Rexx - 變數
- Rexx - 運算子
- Rexx - 陣列
- Rexx - 迴圈
- Rexx - 決策
- Rexx - 數字
- Rexx - 字串
- Rexx - 函式
- Rexx - 堆疊
- Rexx - 檔案 I/O
- Rexx - 檔案函式
- Rexx - 子程式
- Rexx - 內建函式
- Rexx - 系統命令
- Rexx - XML
- Rexx - Regina
- Rexx - 解析
- Rexx - 訊號
- Rexx - 除錯
- Rexx - 錯誤處理
- Rexx - 面向物件
- Rexx - 可移植性
- Rexx - 擴充套件函式
- Rexx - 指令
- Rexx - 實現
- Rexx - Netrexx
- Rexx - Brexx
- Rexx - 資料庫
- 手持式和嵌入式
- Rexx - 效能
- Rexx - 最佳程式設計實踐
- Rexx - 圖形使用者介面
- Rexx - Reginald
- Rexx - Web 程式設計
- Rexx 有用資源
- Rexx - 快速指南
- Rexx - 有用資源
- Rexx - 討論
Rexx - 堆疊
堆疊有時被稱為外部資料佇列,但我們遵循常用用法,將其稱為堆疊。它是一塊邏輯上位於 Rexx 外部的記憶體塊。像 push 和 queue 這樣的指令將資料放入堆疊,而像 pull 和 parse 這樣的指令則從中提取資料。queued 內建函式報告堆疊中有多少項。
讓我們來看一個堆疊的例子。
/* STACK: */ /* */ /* This program shows how to use the Rexx Stack as either a */ /* stack or a queue. */ do j = 1 to 3 push ‘Stack: line #’ || j /* push 3 lines onto the stack */ end do j = 1 to queued() /* retrieve and display LIFO */ pull line say line end do j = 1 to 3 queue ‘Queue: line #’ || j /* queue 3 lines onto the stack */ end do queued() /* retrieve and display FIFO */ pull line say line end exit 0
程式中的第一個 do 迴圈將三行資料放入堆疊。它使用 push 指令來執行此操作。我們對這些行進行編號,以便在以 LIFO 順序檢索它們時,它們的順序是明顯的。
push 指令放入堆疊的專案將以 LIFO 順序檢索 -
do j = 1 to 3 push ‘Stack: line #’ || j /* push 3 lines onto the stack */ end
下一個程式碼塊顯示了使用 queued 內建函式來發現堆疊中行數,以及使用迴圈從堆疊中檢索所有行的用法 -
do j = 1 to queued() /* retrieve and display LIFO */ pull line say line end
由於這三個專案是透過 push 放入堆疊的,因此它們將以 LIFO 順序檢索。
上述程式的輸出如下。
STACK: LINE #3 STACK: LINE #2 STACK: LINE #1
廣告