我正在阅读 Barnes 的书“Programming in Ada 2012”。这是实现第 12.5 节中的堆栈的代码示例。
src/stacks.adb:(主要相关文件)
package body Stacks is
procedure Push(S: in out Stack; X: in Integer) is
begin
S := new Cell'(S,X);
end Push;
procedure Pop(S: in out Stack; X: in out Integer) is
begin
X := S.Value;
S := Stack(S.Next);
end Pop;
function "="(S, T: Stack) return Boolean is
SS: access Cell := S;
TT: access Cell := T;
begin
while SS /= null and TT /= null loop
if SS.Value /= TT.Value then …Run Code Online (Sandbox Code Playgroud)