Delphi Container Class---torderedlist, tstack, Tqueue, Tobjectstack, tobjectqueue use

Source: Internet
Author: User

Torderedlist, Tstack, Tqueue

The CONTNRS unit also defines three other classes: Torderedlist, Tstack, Tqueue

Torderedlist

Torderedlist = Class (TObject) Private    flist:tlist;protected    procedure Pushitem (aitem:pointer); virtual; abstract;    ... public    function Count:integer;    function AtLeast (Acount:integer): Boolean;    Procedure Push (aitem:pointer);    function Pop:pointer;    function Peek:pointer;end;

Tstack

Tstack = Class (torderedlist) protected    procedure Pushitem (aitem:pointer); override;end;

Tqueue

Tqueue = Class (torderedlist) protected    procedure Pushitem (aitem:pointer); override;end;

  

  Note that although torderedlist is not inherited from Tlist, it uses tlist to store pointers when implemented internally. Also note that the pushitem process of the Torderedlist class is a smelly abstract process, so we cannot instantiate the Torderlist class, but we should inherit the new class from torderlist and implement the abstract Pushitem method.

Therefore, the tstack and tqueue inherit from Torderedlist, so the tstack and tqueue pointers also exist in the tlist of their own.

Tstack and Tqueue are classes that implement Pushitem abstract methods, and we can instantiate tstack and Tqueue classes as last-in-first-out stacks (LIFO) and FIFO-first-out queues (FIFO). Here are the instructions for using the methods of these two classes:

    • Count returns the number of items in the list.
    • AtLeast can be used to check the size of the linked list, to determine whether the number of pointers in the current listing is greater than the passed parameter value, and if true, the number of items in the list is greater than the arguments that came in.
    • Push for the Tstack class, the push method adds the pointer to the end of the list, and for the Tqueue class, the push method inserts the pointer at the beginning of the list.
    • POP returns the end pointer to the list and removes it from the linked list.
    • Peek returns the end pointer of the linked list, but does not remove it from the linked list.

Tobjectstack, Tobjectqueue

The last two classes in the Contnrs unit are the Tobjectstack and Tobjectqueue classes, which are defined as follows

Tobjectstack

Tobjectstack = Class (tstack) public    procedure Push (aobject:tobject);    function Pop:tobject;    function Peek:tobject;end;

Tobjectqueue

Tobjectqueue = Class (Tqueue) public    procedure Push (aobject:tobject);    function Pop:tobject;    function Peek:tobject;end;

These two classes are just simple extensions of the tstack and Tqueue classes, which hold TObject object references in the linked list, rather than simple pointers.

Delphi Container Class---torderedlist, tstack, Tqueue, Tobjectstack, tobjectqueue use

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.