其实,动态集合的不同组织方式,可能带来 算法的变化和效率的变化 Program reverse(input,output) var s:stack;c:char 定义栈的管理动作: begin initialize(S):创建一个栈; initialize(s); read (c); push(S,c):将c压入栈S中; while c<>”#”do top(S):栈顶元素; begin push(s,c);read(c); pop(S):将栈顶元素去除; end empty(S):判定S是否为空 while not empty(s)do begin fu(s):判断S是否满 write(top(s)); pop(s); end end其实,动态集合的不同组织方式,可能带来 算法的变化和效率的变化 ◼ 定义栈的管理动作: initialize(S):创建一个栈; push(S,c):将c压入栈S中; top(S):栈顶元素; pop(S):将栈顶元素去除; empty(S):判定S是否为空 full(s):判断S是否满 Program reverse(input, output) var s: stack; c: char begin initialize(s); read (c); while c<>”#” do begin push(s,c);read(c); end while not empty(s) do begin write(top(s)); pop(s); end end