Restricted list queue and stack

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.