Stack类和StackBase类
Stack是一种后进先出的数据结构类型(Last In First Out),只能容纳一种类型,即容器类型(container)。
所以它的push方法的参数是container类型的,我们可以["Something"]这样写。
StackBase是Stack的子类,加强型。这个命名够蛋疼的,不知道的还以为是Stack的父类。StackBase除了
拥有Stack类似的特性外,它还可以容纳任意指定的类型,并增加了索引方法peek。
代码如下
static void StackJob(Args _args)
{
Stack m_stack = new Stack();
StackBase m_stackBase = new StackBase(Types::String);
;
m_stack.push(["Item001"]);
m_stack.push(["Item002"]);
info(strfmt("%1",m_stack.qty())); // 2
info(strfmt("%1",conpeek(m_stack.pop(),1))); //Item002
info(strfmt("%1",conpeek(m_stack.pop(),1))); //Item001
info("=============");
m_stackBase.push("A");
m_stackBase.push("B");
info(strfmt("%1",m_stackBase.count())); // 2
info(strfmt("%1",m_stackBase.peek(2))); // B
info(strfmt("%1",m_stackBase.pop())); //B
info(strfmt("%1",m_stackBase.pop())); //A
}
{
Stack m_stack = new Stack();
StackBase m_stackBase = new StackBase(Types::String);
;
m_stack.push(["Item001"]);
m_stack.push(["Item002"]);
info(strfmt("%1",m_stack.qty())); // 2
info(strfmt("%1",conpeek(m_stack.pop(),1))); //Item002
info(strfmt("%1",conpeek(m_stack.pop(),1))); //Item001
info("=============");
m_stackBase.push("A");
m_stackBase.push("B");
info(strfmt("%1",m_stackBase.count())); // 2
info(strfmt("%1",m_stackBase.peek(2))); // B
info(strfmt("%1",m_stackBase.pop())); //B
info(strfmt("%1",m_stackBase.pop())); //A
}