Queues and stacks are restricted lists, queues are first-in, first-out lists, and stacks are first-in-a-list, and the implementation of the list can be viewed http://my.oschina.net/u/2011113/blog/514713 .
The structure diagram is
The queue implements the Iqueue interface, whose code is as follows:
package tunie.struct.group{/** * tunie * oct 9, 2015 3:09:59 pm * <b>queue main functions are as follows </b> * <li> queue */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;}}}
Its interface is defined as follows:
Package tunie.struct.group{/** * Tunie * Oct 9, 2:51:37 PM * <b>iqueue main functions as follows </b> * <li> Queue */public Interface Iqueue extends igroup{/** * Queue (Team tail in), team changes * @param value */function inQueue (value:*): void;/** * out of the team (team head out), the team changes * @return */function outqueue ():*;/** * Read the team head, the team does not change * @return */function frontqueue ():*;/** * Get value based on queue index * @param index * @ return */function obtain (Index:int):*;}}
And put out the definition of istack.
Package tunie.struct.group{/** * Tunie * Oct 9, 3:13:32 PM * <b>istack main functions as follows </b> * <li> Stack */public i Nterface Istack extends igroup{/** * into the stack, stack changes * @param value */function push (value:*): void;/** * out of stack, stack changes * @return */fun Ction pop ():*;/*** based on queue index * @param index* @return */function obtain (Index:int):*;}}
The implementation is basically the same as the queue, no code is posted.
Restricted list queue and stack