码迷,mamicode.com
首页 > 其他好文 > 详细

受限列表 队列与栈

时间:2015-10-09 17:02:48      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

        队列与栈为受限列表,队列为先入先出型列表,而栈为先入后出型列表,有关列表的实现可以查看 http://my.oschina.net/u/2011113/blog/514713 。

        结构图为

技术分享

Queue实现了IQueue接口,其代码如下所示:

package tunie.struct.group
{
	/**
	 * Tunie
	 * Oct 9, 2015 3:09:59 PM
	 * <b>Queue主要功能如下</b>
	 * <li>队列
	 */
	public class Queue extends Group implements IGroup, IQueue
	{
		protected var _list:IList;
		
		public function Queue()
		{
			_list = new ArrayList();
		}
		
		public function inQueue(value:*):void
		{
			_list.add(value);
		}
		
		public function outQueue():*
		{
			return _list.removeAt(0);
		}
		
		public function frontQueue():*
		{
			return _list.obtain(0);
		}
		
		public function obtain(index:int):*
		{
			return _list.obtain(index);
		}
		
		override public function clear():void
		{
			_list.clear();
		}
		
		override public function contain(value:*):Boolean
		{
			return _list.contain(value);
		}
		
		override public function get isEmpty():Boolean
		{
			return _list.isEmpty;
		}
		
		override public function get size():int
		{
			return _list.size;
		}
		
		
	}
}

其接口定义如下:

package tunie.struct.group
{
	/**
	 * Tunie
	 * Oct 9, 2015 2:51:37 PM
	 * <b>IQueue主要功能如下</b>
	 * <li>队列
	 */
	public interface IQueue extends IGroup
	{
		/**
		 * 入队(队尾入),队发生变化
		 * @param value
		 */
		function inQueue(value:*):void;
		/**
		 * 出队(队头出),队发生变化
		 * @return 
		 */
		function outQueue():*;
		/**
		 * 读队头,队不发生变化
		 * @return 
		 */
		function frontQueue():*;
		/**
		 * 根据队列索引取得值 
		 * @param index
		 * @return 
		 */
		function obtain(index:int):*;
	}
}

再贴出IStack的定义

package tunie.struct.group
{
	/**
	 * Tunie
	 * Oct 9, 2015 3:13:32 PM
	 * <b>IStack主要功能如下</b>
	 * <li>栈
	 */
	public interface IStack extends IGroup
	{
		/**
		 * 入栈,栈发生变化
		 * @param value
		 */
		function push(value:*):void;
		/**
		 * 出栈,栈发生变化
		 * @return 
		 */
		function pop():*;
		/**
		* 根据队列索引取得值 
		* @param index
		* @return 
		*/
		function obtain(index:int):*;
	}
}

实现跟Queue基本一样,就不贴出代码了。

受限列表 队列与栈

标签:

原文地址:http://my.oschina.net/u/2011113/blog/514818

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!