Queue--c++ Implementation

Source: Internet
Author: User

Queue is one of the commonly used data structures, can be easily implemented by the table, in order to understand the principle, we use the array to implement

1 /************************************************************************/2 /*the implementation of the queue, which can be implemented directly through the table, is implemented using an array3 /************************************************************************/4 5 #ifndef Queue_h6 7 #defineQueue_h8 9#include <assert.h>Ten  One namespaceSTL A { -Template <typename object> -     classQueue the     { -Queue (intqueuesize) -: Front (0) -, Rear (1) +, Size (0) - , Capacity (queuesize) +         { AArray =NewObject[queuesize]; at         } -  -~Queue () -         { - assert (Array); -             Delete[] Array; in         } -  to         //Queue function +         voidEnQueue (Object x) -         { the             if(Isfull ()) *             { $                 Throw();Panax Notoginseng             } -array[rear++] =x; theRear = (++rear)%capacity; +++Size; A         } the  +         //out Team function -         voidDeQueue () $         { $             if(IsEmpty ()) -             { -                 Throw(); the             } -++Front;Wuyi--Size; the         } -  Wu         BOOLisfull () -         { About             returnSize = =capacity; $         } -  -         BOOLIsEmpty () -         { A             returnSize = =0; +         } the  -     Private: $object*Array; the         intcapacity;//Maximum queue capacity the         intFront;//Queue Header Position the         intRear;//position at the end of the queue the         intSize;//number of objects in the queue -     }; in } the #endif // ! Queue_h

Queue--c++ Implementation

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.