Queue. h

Source: Internet
Author: User
View code

 1   Const     Int  Maxqueue  =     50  ;
2
3 Enum Error_code
4 {
5 Success, overflow, underflow, fail // No;
6 };
7
8 Template < Class T >
9 Class Queue
10 {
11 Public :
12 Queue ();
13 Bool Empty () Const ;
14 Error_code serve ();
15 Error_code append ( Const T & ITEM );
16 Error_code retrieve (T & Item) Const ;
17 Protected :
18 Int Count;
19 Int Front, rear;
20 T entry [maxqueue];
21 };
22
23 Template < Class T >
24 Queue < T > : Queue ()
25 {
26 Count = 0 ;
27 Rear = Maxqueue - 1 ;
28 Front = 0 ;
29 }
30
31 Template < Class T >
32 Bool Queue < T > : Empty () Const
33 {
34 Return Count = 0 ;
35 }
36
37 Template < Class T >
38 Error_code queue < T > : Append ( Const T & Item)
39 {
40 If (Count > = Maxqueue)
41 Return Overflow;
42 Count ++ ;
43 Rear = (Rear + 1 ) = Maxqueue) ? 0 :( Rear + 1 );
44 Entry [rear] = Item;
45 Return Success;
46 }
47
48 Template < Class T >
49 Error_code queue < T > : Serve ()
50 {
51 If (Count <= 0 )
52 Return Underflow;
53 Count -- ;
54 Front = (Front + 1 ) = Maxqueue) ? 0 :( Front + 1 );
55 Return Success;
56 }
57
58 Template < Class T >
59 Error_code queue < T > : Retrieve (T & Item) Const
60 {
61 If (Count <= 0 )
62 Return Underflow;
63 Item = Entry [Front];
64 Return Success;
65 }

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.