Queue - empty and full access to the team

code show as below:

. 1 #include <the iostream>
 2  the using  namespace STD;
 . 3  // queue 
. 4  struct Queue
 . 5  {
 . 6      int A [ 100 ]; 
 . 7      int Front;
 . 8      int REAR;
 . 9  } Q;
 10  int n-; // save space for the actual n + 1, that is 0-n. 
11  // team full 
12 is  BOOL isFull ()
 13 is  {
 14      return (+ q.rear . 1 )% (n-+ . 1 ) == q.front;
 15 }
16 //队空 
17 bool isempty()
18 {
19     return q.rear==q.front;
20 }
21 //入队
22 void inq(int x)
23 {
24     if(!isfull())
25     {
26         q.a[q.rear]=x;
27         q.rear= (q.rear+1)%(n+1);
28     }
29     else
30     {
31         cout<<"The queue is full.";
32     }
33 }
34 //出队
35 int outq()
36 {
37     int t;
38     if(isempty())
39     {
40         cout<<"The queue is empty.";
41         return -1;
42     }
43     else
44     {
45         t=q.a[q.front];
46         q.front=(q.front+1)%(n+1);
 47          return T;
 48      }
 49  }
 50  main ()
 51 is  {
 52 is      q.front = 0 ;
 53 is      q.rear = 0 ;
 54 is      CIN >> n-;
 55      for ( int T, I = . 1 ; I <= n- ; I ++ )
 56 is      {
 57 is          CIN >> T;
 58          INQ (T);
 59      }
 60      INQ ( 100 ); // full team into the team, given 
61 is      for ( int= I . 1 ; I <= n-; I ++ )
 62 is      {
 63 is          COUT << OUTQ () << "  " ;
 64      }
 65      COUT << OUTQ (); // Empty Team dequeued given 
66 }

 

Guess you like

Origin www.cnblogs.com/wanjinliu/p/11415614.html