软件工程

本类阅读TOP10

·PHP4 + MYSQL + APACHE 在 WIN 系统下的安装、配置
·Linux 入门常用命令(1)
·Linux 入门常用命令(2)
·使用 DCPROMO/FORCEREMOVAL 命令强制将 Active Directory 域控制器降级
·DirectShow学习(八): CBaseRender类及相应Pin类的源代码分析
·基于ICE方式SIP信令穿透Symmetric NAT技术研究
·Windows 2003网络负载均衡的实现
·一网打尽Win十四种系统故障解决方法
·数百种 Windows 软件的免费替代品列表
·收藏---行百里半九十

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
使用链表(LinkedList) mix-in 到其中的栈(Stack)

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

//****************************************************************************
// FileName: Stack.as
// Description:Stack
// Author: AOL
// Last Modified:14/10/2003
//****************************************************************************
import net.flash8.ds.LinkedList;
class net.flash8.ds.Stack
{
        private var stackList:LinkedList;
        
        // constructor
        public function Stack()
        {
                stackList = new LinkedList("stack");
        }
        
        // add object to stack
        public function push(object:Object):Void
        {
                stackList.insertAtFront(object);
        }
        // remove object from stack
        public function pop():Object
        {
                return stackList.removeFromFront();
        }
        // determine if stack is empty
        public function isEmpty():Boolean
        {
                return stackList.isEmpty();
        }
        // output stack contents
        public function print():Void
        {
                stackList.print();
        }
}
// end class Stack

//SatckTest.fla
import net.flash8.ds.Stack;
import net.flash8.ds.EmptyListError;
var stack = new Stack();
// create objects to store in the stack
var bool:Boolean = true;
var integer:Number = 12324;
var string:String = "hello";
var movieClip:MovieClip = new MovieCip("movie clip");
// use push method
stack.push(bool);
stack.print();
stack.push(integer);
stack.print();
stack.push(string);
stack.print();
stack.push(movieClip);
stack.print();

// remove items from stack
try
{
        var removedObject:Object = null;
        for(var i:Number=1;i<6;i++)
        {
                removedObject = stack.pop();
                trace(removedObject.toString()+" popped");
                stack.print();
        }
}
// catch exception if stack empty when item popped
catch (emptyListError)
{
        emptyListError.messageTrace();
}
output出的结果:

/=======begin of the stack table ===========\
true
\=========end of the stack table ===========/

 

/=======begin of the stack table ===========\
12324
true
\=========end of the stack table ===========/

 

/=======begin of the stack table ===========\
hello
12324
true
\=========end of the stack table ===========/

 

/=======begin of the stack table ===========\
undefined
hello
12324
true
\=========end of the stack table ===========/

 

undefined popped
/=======begin of the stack table ===========\
hello
12324
true
\=========end of the stack table ===========/

 

hello popped
/=======begin of the stack table ===========\
12324
true
\=========end of the stack table ===========/

 

12324 popped
/=======begin of the stack table ===========\
true
\=========end of the stack table ===========/

 

true popped
Empty stack
An EmptyListError:The stack is empty




相关文章

相关软件