齐桡吧 关注:9贴子:1,329
  • 11回复贴,共1
  • 222.174.42.*
1楼2005-10-13 10:26回复
    #include<iostream.h>

     #define QueueMax 10
     #define ERROR 0
     #define OK 1

     typedef int ElemType;
     //head define....................
     //==================================================================
     class Queue_c
     {

     ElemType Q[QueueMax];
     ElemType Queue_c_temp;
     int front,rear;

     public:
     Queue_c()
     {
    // for(i=0;i<QueueMax;i++)Q[i]=0;
     front=rear=0;
     }
     ~Queue_c(){}
     //basic information of the class Queue_c
     void ZeroQueue();
     int QFull();
     int QEmpty();
     int EnQueue(ElemType e);
     ElemType DeQueue();
     int GetNumber();
     void ShowAll();

     };
     //define of the class Queue_c...........................
     //------------------------------------------------------------------
    class Producer_c
     {
     ElemType goods;
     public:
     int produce(Queue_c buffur,Consumer_c consumer);
     int produce(Queue_c buffur);

     };
     //define of class Producer_c
     //------------------------------------------------------------------
     class Consumer_c
     {
     ElemType goods;
     public:
     int consume(Queue_c buffur,Producer_c producer);
     int consume(Queue_c buffur);
     };
     //difine of class Consumer_c
     //==================================================================
     void main()
     {
     Queue_c buffur;
     Producer_c producer;
     Consumer_c consumer;
     //int judge=1;
     //char ExitLoop='n';
     buffur.ZeroQueue();
     cout<<"===================="<<endl;
    /* while('y'!=ExitLoop)
     { judge%=2;
     if(1==judge)producer.produce(buffur,consumer);
     if(0==judge)consumer.consume(buffur,producer);
     cout<<"============="<<endl;
     cout<<"=1 produce ="<<endl;
     cout<<"=2 consume ="<<endl;
     cout<<"=others exit="<<endl;
     cout<<"============="<<endl;
     cin>>judge;
     if(1==judge)cout<<"you pressed 1,product"<<endl;
     if(2==judge)cout<<"you pressed 2,consume"<<endl;

     if(1!=judge&&2!=judge){ExitLoop='y';break;}
     } */
     producer.produce(buffur,consumer);
     consumer.consume(buffur,producer);


    /* buffur.QFull();
     buffur.QEmpty();
     buffur.EnQueue(100);
     buffur.QEmpty();
     buffur.ShowAll();
     buffur.DeQueue();
     buffur.QEmpty(); */
     buffur.ShowAll();
     cout<<buffur.GetNumber()<<endl;

    }

    /*********************************************************************/
     void Queue_c::ZeroQueue()
     {
     int i;
     for(i=0;i<QueueMax;i++)Q[i]=0;
     }

     int Queue_c::QFull()
     {
     if((rear+1)%QueueMax==front)
     {cout<<"Queue is full"<<endl;
     return OK;
     }
     else return ERROR;
     }

     //QFull...................
     int Queue_c::QEmpty()
     {
     if(rear==front)
     {
     cout<<"Queue is Empty"<<endl;
     return OK;
     }
     else return ERROR;
     }
     //QEmpty..........................

     int Queue_c::EnQueue(ElemType e)
     {
     if(QFull())return ERROR;
     Q[rear]=e;
     rear=(rear+1)%QueueMax;
     return OK;
     }


     //EnQueue.........................

     ElemType Queue_c::DeQueue()
     {
     if(QEmpty())return ERROR;
     Queue_c_temp=Q[front];
     Q[front]=0;
     front=(front+1)%QueueMax;
     return OK;
     }
     //DeQueue.......................
     int Queue_c::GetNumber()
     {int i;
     i=((rear-front+QueueMax)%QueueMax);
     return i;
     }


     //GetNumber.......................
     void Queue_c::ShowAll()
     {int i;
     for(i=0;i<QueueMax;i++)
     cout<<Q[i]<<" ";
     cout<<endl;
     }

     //ShowAll.........................
    /*********************************************************************/


     int Producer_c::produce(Queue_c buffur,Consumer_c consumer);
     {
     if(buffur.QFull())
     {
     cout<<"ERROR:you must consume a product"<<endl;
     consumer.consume(buffur);
     }
     cout<<"Produce:please input a number"<<endl;
     cin>>goods;
     buffur.EnQueue(goods);
     return OK;
     }
     //produce_A...........................
     int Producer_c::produce(Queue_c buffur)
     {
     cout<<"Produce:please input a number"<<endl;
     cin>>goods;
     buffur.EnQueue(goods);
     return OK;
     }//produce_B..........................
     //class Producer_c
     //******************************************************************


     int Consumer_c::consume(Queue_c buffur,Producer_c producer)
     {
     if(buffur.QEmpty())
     {
     cout<<"ERROR:Need produce"<<endl;
     producer.produce(buffur);
     }

     goods=buffur.DeQueue();
     cout<<"Consume:you have killed"<<goods<<endl;
     return OK;
     }//consume_A..........................

     int Consumer_c::consume(Queue_c buffur)
     {
    goods=buffur.DeQueue();
    cout<<"Consume"<<goods<<"has been killed"<<endl;
    return OK;
     }


    禁言 |2楼2005-10-16 19:02
    回复
      http://www.bcqx.com/free3/gcqsf/


      禁言 |3楼2005-10-16 19:08
      回复
        • 218.56.138.*
        #include<iostream.h>

         #define QueueMax 10
         #define ERROR 0
         #define OK 1

         typedef int ElemType;
         //head define....................
         //==================================================================
         class Queue_c
         {

         ElemType Q[QueueMax];
         ElemType Queue_c_temp;
         int front,rear;

         public:
         Queue_c()
         {
        // for(i=0;i<QueueMax;i++)Q[i]=0;
         front=1;
         rear=0;
         }
         ~Queue_c(){}
         //basic information of the class Queue_c
         void ZeroQueue();
         int QFull();
         int QEmpty();
         int EnQueue(ElemType e);
         ElemType DeQueue();
         int GetNumber();
         void ShowAll();

         };
         //define of the class Queue_c...........................
         //------------------------------------------------------------------
        class Consumer_c
         {
         ElemType goods;
         public:
         int consume(Queue_c &buffur);
         };
         //difine of class Consumer_c
         //==================================================================
         /***************************************************************************************
         ****************************************************************************************/
         void main()
         {
         Queue_c buffur;
         Consumer_c consumer;
         //int judge=1;
         //char ExitLoop='n';
         buffur.ZeroQueue();
         cout<<"===================="<<endl;
        buffur.ShowAll();
         consumer.consume(buffur);

        /* buffur.QFull();
         buffur.QEmpty();
         buffur.EnQueue(100);
         buffur.QEmpty(); */

        /* buffur.DeQueue();
         buffur.QEmpty(); */
         buffur.ShowAll();
         cout<<buffur.GetNumber()<<endl;

        }

        /*****************************************************************************************
        *****************************************************************************************/

         void Queue_c::ZeroQueue()
         {
         int i;
         for(i=0;i<QueueMax;i++)Q[i]=i+1;
         }

         int Queue_c::QFull()
         {
         if((rear+1)%QueueMax==front)
         {cout<<"Queue is full"<<endl;
         return OK;
         }
         else return ERROR;
         }

         //QFull...................
         int Queue_c::QEmpty()
         {
         if(rear==front)
         {
         cout<<"Queue is Empty"<<endl;
         return OK;
         }
         else return ERROR;
         }
         //QEmpty..........................

         int Queue_c::EnQueue(ElemType e)
         {
         if(QFull())return ERROR;
         Q[rear]=e;
         rear=(rear+1)%QueueMax;
         return OK;
         }


         //EnQueue.........................

         ElemType Queue_c::DeQueue()
         {
         if(QEmpty())return ERROR;
         Queue_c_temp=Q[front];
         Q[front]=0;
         front=(front+1)%QueueMax;
         return Queue_c_temp;
         }
         //DeQueue.......................
         int Queue_c::GetNumber()
         {int i;
         i=((rear-front+QueueMax)%QueueMax);
         return i;
         }


         //GetNumber.......................
         void Queue_c::ShowAll()
         {int i;
         for(i=0;i<QueueMax;i++)
         cout<<Q[i]<<" ";
         cout<<endl;
         }

         //ShowAll.........................
        /******************************************************************/

         int Consumer_c::consume(Queue_c &buffur)
         {
        goods=buffur.DeQueue();
        cout<<"Consume "<<goods<<" has been killed"<<endl;
        return OK;
         }


        5楼2005-10-17 10:58
        回复
          • 218.56.138.*
          #include<iostream.h> 

           #define QueueMax 10 
           #define ERROR 0 
           #define OK 1 

           typedef int ElemType;
           //head define....................
          /*****************************************************************************************/
           class Queue_c
           {

           ElemType Q[QueueMax];
           ElemType Queue_c_temp;
           int front,rear;

           public:
           //basic information of the class Queue_c
           void ZeroQueue();
           int QFull();
           int QEmpty();
           int EnQueue(ElemType e);
           ElemType DeQueue();
           int GetNumber();
           void ShowAll();

           };
           //define of the class Queue_c...........................
           //===================================================================
          class Producer_c
           {
           ElemType goods;
           public:
           int produce(Queue_c &buffur);

           };
           //define of class Producer_c
          /******************************************************************************************
          ******************************************************************************************/
           void main()
           {
           Queue_c buffur;
           Producer_c producer;
           //int judge=1;
           //char ExitLoop='n';
           buffur.ZeroQueue();
           cout<<"===================="<<endl;

           producer.produce(buffur);



          /* buffur.QFull();
           buffur.QEmpty();
           buffur.EnQueue(100);
           buffur.QEmpty();
           buffur.ShowAll();
           buffur.DeQueue();
           buffur.QEmpty(); */
           buffur.ShowAll();
           cout<<buffur.GetNumber()<<endl;

          }

          /*********************************************************************/
           void Queue_c::ZeroQueue()
           {
           int i;
           for(i=0;i<QueueMax;i++)Q[i]=0;
           rear=front=0;
           }

           int Queue_c::QFull()
           {
           if((rear+1)%QueueMax==front)
           {cout<<"Queue is full"<<endl;
           return OK;
           }
           else return ERROR;
           }

           //QFull...................
           int Queue_c::QEmpty()
           {
           if(rear==front)
           {
           cout<<"Queue is Empty"<<endl;
           return OK;
           }
           else return ERROR;
           }
           //QEmpty..........................

           int Queue_c::EnQueue(ElemType e)
           {
           if(QFull())return ERROR;
           Q[rear]=e;
           rear=(rear+1)%QueueMax;
           return OK;
           }


           //EnQueue.........................

           ElemType Queue_c::DeQueue()
           {
           if(QEmpty())return ERROR;
           Queue_c_temp=Q[front];
           Q[front]=0;
           front=(front+1)%QueueMax;
           return Queue_c_temp;
           }
           //DeQueue.......................
           int Queue_c::GetNumber()
           {int i;
           i=((rear-front+QueueMax)%QueueMax);
           return i;
           }


           //GetNumber....................... 
           void Queue_c::ShowAll() 
           {int i; 
           for(i=0;i<QueueMax;i++) 
           cout<<Q[i]<<" "; 
           cout<<endl; 
           } 

           //ShowAll......................... 
          /*********************************************************************/ 
           int Producer_c::produce(Queue_c &buffur) 
           { 
           cout<<"Produce:please input a number"<<endl; 
           cin>>goods; 
           buffur.EnQueue(goods); 
           return OK; 
           }//produce_B.......................... 
           //class Producer_c 
           //******************************************************************


          6楼2005-10-17 11:05
          回复
            • 218.56.138.*
            #include<iostream.h>

             #define QueueMax 10 
             #define ERROR 0 
             #define OK 1 
             #define SHOW buffur.ShowAll();

             typedef int ElemType;
             //head define....................
            /*****************************************************************************************/
             class Queue_c
             {

             ElemType Q[QueueMax];
             ElemType Queue_c_temp;
             int front,rear;

             public:
             //basic information of the class Queue_c
             void ZeroQueue();
             int QFull();
             int QEmpty();
             int EnQueue(ElemType e);
             ElemType DeQueue();
             int GetNumber();
             void ShowAll();

             };
             //define of the class Queue_c...........................
             //===================================================================
            class Producer_c
             {
             ElemType goods;
             public:
             int produce(Queue_c &buffur);

             };
             //define of class Producer_c
             //===================================================================
            class Consumer_c
             {
             ElemType goods;
             public:
             int consume(Queue_c &buffur);
             };
             //difine of class Consumer_c
            /******************************************************************************************
            ******************************************************************************************/
             void main()
             {
             Queue_c buffur;
             Producer_c producer;
             Consumer_c consumer;
             //int judge=1;
             //char ExitLoop='n';
             buffur.ZeroQueue();
             cout<<"===================="<<endl;
             SHOW
             producer.produce(buffur);
             SHOW
             consumer.consume(buffur);
             SHOW
             consumer.consume(buffur);
             buffur.ShowAll();
             cout<<buffur.GetNumber()<<endl;

            }
            /*****************************************************************************************
            ******************************************************************************************/
             void Queue_c::ZeroQueue()
             {
             int i;
             for(i=0;i<QueueMax;i++)Q[i]=0;
             rear=front=0;
             }
             //zzzzzzzzzzzzzzzz
             int Queue_c::QFull()
             {
             if((rear+1)%QueueMax==front)
             {cout<<"Queue is full"<<endl;
             return OK;
             }
             else return ERROR;
             }

             //QFull...................
             int Queue_c::QEmpty()
             {
             if(rear==front)
             {
             cout<<"Queue is Empty"<<endl;
             return OK;
             }
             else return ERROR;
             }
             //QEmpty..........................

             int Queue_c::EnQueue(ElemType e)
             {
             if(QFull())return ERROR;
             Q[rear]=e;
             rear=(rear+1)%QueueMax;
             return OK;
             }


             //EnQueue.........................

             ElemType Queue_c::DeQueue()
             {
             if(QEmpty())return ERROR;
             Queue_c_temp=Q[front];
             Q[front]=0;
             front=(front+1)%QueueMax;
             return Queue_c_temp;
             }
             //DeQueue.......................
             int Queue_c::GetNumber()
             {int i;
             i=((rear-front+QueueMax)%QueueMax);
             return i;
             }


             //GetNumber.......................
             void Queue_c::ShowAll()
             {int i;
             for(i=0;i<QueueMax;i++)
             cout<<Q[i]<<" ";
             cout<<endl;
             }

             //ShowAll.........................
            /*******************************************************************/
             int Producer_c::produce(Queue_c &buffur)
             {
             cout<<"Produce:please input a number"<<endl;
             cin>>goods;
             buffur.EnQueue(goods);
             return OK;
             }//produce_B..........................
             //class Producer_c
            /********************************************************************/

             int Consumer_c::consume(Queue_c &buffur)
             {
            goods=buffur.DeQueue();
            cout<<"Consume "<<goods<<" has been killed"<<endl;
            return OK;
             }
             /*********************************************************************/


            7楼2005-10-17 11:15
            回复
              • 218.56.138.*
              #include<iostream.h>

               #define QueueMax 10 
               #define ERROR 0 
               #define OK 1 
               #define SHOW buffur.ShowAll();

               typedef int ElemType;
               //head define....................
              /*****************************************************************************************/
               class Queue_c
               {

               ElemType Q[QueueMax];
               ElemType Queue_c_temp;
               int front,rear;

               public:
               //basic information of the class Queue_c
               void ZeroQueue();
               int QFull();
               int QEmpty();
               int EnQueue(ElemType e);
               ElemType DeQueue();
               int GetNumber();
               void ShowAll();

               };
               //define of the class Queue_c...........................
               //===================================================================
              class Producer_c
               {
               ElemType goods;
               public:
               int produce(Queue_c &buffur);

               };
               //define of class Producer_c
               //===================================================================
              class Consumer_c
               {
               ElemType goods;
               public:
               int consume(Queue_c &buffur,Producer_c producer); 
               int consume(Queue_c &buffur);
               };
               //difine of class Consumer_c
              /******************************************************************************************
              ******************************************************************************************/
               void main()
               {
               Queue_c buffur;
               Producer_c producer;
               Consumer_c consumer;
               //int judge=1;
               //char ExitLoop='n';
               buffur.ZeroQueue();
               cout<<"===================="<<endl;
               SHOW
               producer.produce(buffur);
               SHOW
               consumer.consume(buffur,producer);
               SHOW
               consumer.consume(buffur,producer);
               buffur.ShowAll();
               cout<<buffur.GetNumber()<<endl;

              }
              /*****************************************************************************************
              ******************************************************************************************/
               void Queue_c::ZeroQueue()
               {
               int i;
               for(i=0;i<QueueMax;i++)Q[i]=0;
               rear=front=0;
               }
               //zzzzzzzzzzzzzzzz
               int Queue_c::QFull()
               {
               if((rear+1)%QueueMax==front)
               {cout<<"Queue is full"<<endl;
               return OK;
               }
               else return ERROR;
               }

               //QFull...................
               int Queue_c::QEmpty()
               {
               if(rear==front)
               {
               cout<<"Queue is Empty"<<endl;
               return OK;
               }
               else return ERROR;
               }
               //QEmpty..........................

               int Queue_c::EnQueue(ElemType e)
               {
               if(QFull())return ERROR;
               Q[rear]=e;
               rear=(rear+1)%QueueMax;
               return OK;
               }


               //EnQueue.........................

               ElemType Queue_c::DeQueue()
               {
               if(QEmpty())return ERROR;
               Queue_c_temp=Q[front];
               Q[front]=0;
               front=(front+1)%QueueMax;
               return Queue_c_temp;
               }
               //DeQueue.......................
               int Queue_c::GetNumber()
               {int i;
               i=((rear-front+QueueMax)%QueueMax);
               return i;
               }


               //GetNumber.......................
               void Queue_c::ShowAll()
               {int i;
               for(i=0;i<QueueMax;i++)
               cout<<Q[i]<<" ";
               cout<<endl;
               }

               //ShowAll.........................
              /*******************************************************************/



               //produce_A........................... 

               int Producer_c::produce(Queue_c &buffur)
               {
               cout<<"Produce:please input a number"<<endl;
               cin>>goods;
               buffur.EnQueue(goods);
               return OK;
               }//produce_B..........................
               //class Producer_c
              /********************************************************************/

               int Consumer_c::consume(Queue_c &buffur,Producer_c producer)
               {
               if(buffur.QEmpty())
               {
               cout<<"ERROR:Need produce"<<endl;
               producer.produce(buffur);
               return ERROR;
               }

               goods=buffur.DeQueue();
               cout<<"Consume:you have killed "<<goods<<endl;
               return OK;
               }//consume_A..........................

               int Consumer_c::consume(Queue_c &buffur)
               {
              goods=buffur.DeQueue();
              cout<<"Consume "<<goods<<" has been killed"<<endl;
              return OK;
               }
              /*********************************************************************/


              8楼2005-10-17 11:30
              回复
                • 218.56.138.*
                http://www.skycn.com/soft/3066.html


                9楼2005-10-19 14:10
                回复
                  • 218.56.138.*
                  #include<iostream.h> 

                   #define QueueMax 10 
                   #define ERROR 0 
                   #define OK 1 
                   #define SHOW buffur.ShowAll(); 

                   typedef int ElemType; 

                   ElemType goods;
                   //head define.................... 
                  /*****************************************************************************************/ 
                   class Queue_c 
                   { 

                   ElemType Q[QueueMax]; 
                   ElemType Queue_c_temp; 
                   int front,rear; 

                   public: 
                   //basic information of the class Queue_c 
                   void ZeroQueue(); 
                   int QFull(); 
                   int QEmpty(); 
                   int EnQueue(ElemType e); 
                   ElemType DeQueue(); 
                   int GetNumber(); 
                   void ShowAll(); 

                   }; 
                   //define of the class Queue_c........................... 
                   //=================================================================== 

                  class Producer_c 
                   { 
                   public: 
                   ElemType goods; 
                   int produce(Queue_c &buffur); 
                   }; 
                   //=================================================================== 
                  class Consumer_c 
                   { 
                   ElemType goods; 
                   public: 
                   int consume(Queue_c &buffur,Producer_c producer); 
                   int consume(Queue_c &buffur); 
                   }; 
                   //difine of class Consumer_c 
                  //===================================================================
                   
                  /****************************************************************************************** 
                  ******************************************************************************************/ 
                   void main()
                   {
                   Queue_c buffur;
                   Producer_c producer;
                   Consumer_c consumer;
                   int judge=1;
                   char ExitLoop='n';
                   buffur.ZeroQueue();
                   cout<<"===================="<<endl;
                   SHOW


                  while('y'!=ExitLoop)
                   { judge%=2;
                   if(1==judge)producer.produce(buffur);
                   if(0==judge)consumer.consume(buffur,producer);
                   cout<<"============="<<endl;
                   cout<<"=1 produce ="<<endl;
                   cout<<"=2 consume ="<<endl;
                   cout<<"=others exit="<<endl;
                   cout<<"============="<<endl;
                   cin>>judge;

                   if(1==judge){
                   cout<<"you pressed 1,product"<<endl;
                   if(buffur.QFull()){judge=2;continue;}
                   }

                   if(2==judge){
                   cout<<"you pressed 2,consume"<<endl;
                   if(buffur.QEmpty()){judge=1;continue;}
                   }
                   if(1!=judge&&2!=judge){ExitLoop='y';break;}
                   }

                  SHOW


                   /*producer.produce(buffur);
                   SHOW
                   consumer.consume(buffur,producer);
                   SHOW 
                   consumer.consume(buffur,producer); 
                   buffur.ShowAll(); 
                   cout<<buffur.GetNumber()<<endl; */


                  /***************************************************************************************** 
                  ******************************************************************************************/ 
                   void Queue_c::ZeroQueue() 
                   { 
                   int i; 
                   for(i=0;i<QueueMax;i++)Q[i]=0; 
                   rear=front=0; 
                   } 
                   //zzzzzzzzzzzzzzzz 
                   int Queue_c::QFull() 
                   { 
                   if((rear+1)%QueueMax==front) 
                   {cout<<"Queue is full"<<endl; 
                   return OK; 
                   } 
                   else return ERROR; 
                   } 

                   //QFull................... 
                   int Queue_c::QEmpty() 
                   { 
                   if(rear==front) 
                   { 
                   cout<<"Queue is Empty"<<endl; 
                   return OK; 
                   } 
                   else return ERROR; 
                   } 
                   //QEmpty.......................... 

                   int Queue_c::EnQueue(ElemType e) 
                   { 
                   if(QFull())return ERROR; 
                   Q[rear]=e; 
                   rear=(rear+1)%QueueMax; 
                   return OK; 
                   } 


                   //EnQueue......................... 

                   ElemType Queue_c::DeQueue() 
                   { 
                   if(QEmpty())return ERROR; 
                   Queue_c_temp=Q[front]; 
                   Q[front]=0; 
                   front=(front+1)%QueueMax; 
                   return Queue_c_temp; 
                   } 
                   //DeQueue....................... 
                   int Queue_c::GetNumber() 
                   {int i; 
                   i=((rear-front+QueueMax)%QueueMax); 
                   return i; 
                   } 


                   //GetNumber....................... 
                   void Queue_c::ShowAll() 
                   {int i; 
                   for(i=0;i<QueueMax;i++) 
                   cout<<Q[i]<<" "; 
                   cout<<endl; 
                   } 

                   //ShowAll......................... 
                  /*******************************************************************/ 
                  /*int produce(Producer_c &producer,Queue_c &buffur,Consumer_c consumer); 
                   { 
                   if(buffur.QFull()) 
                   { 
                   cout<<"ERROR:you must consume a product"<<endl; 
                   consumer.consume(buffur); 
                   } 
                   cout<<"Produce:please input a number"<<endl; 
                   cin>>producer.goods; 
                   buffur.EnQueue(producer.goods); 
                   return OK; 
                   } //produce_A........................... 
                  */
                  //--------------------------------------------------------------------
                   int Producer_c::produce(Queue_c &buffur) 
                   { 
                   
                   if(buffur.QFull()) 
                   { 
                   cout<<"ERROR:you must consume a product"<<endl; 
                   return ERROR;
                   } 

                   cout<<"Produce:please input a number"<<endl; 
                   cin>>goods; 
                   buffur.EnQueue(goods);
                   return OK; 
                   }//produce_B..........................
                   //class Producer_c 
                  /********************************************************************/ 

                   int Consumer_c::consume(Queue_c &buffur,Producer_c producer) 
                   { 
                   if(buffur.QEmpty()) 
                   { 
                   cout<<"ERROR:Need produce"<<endl; 
                   producer.produce(buffur); 
                   return ERROR; 
                   } 

                   goods=buffur.DeQueue(); 
                   cout<<"Consume:you have killed "<<goods<<endl; 
                   return OK; 
                   }//consume_A.......................... 
                  //--------------------------------------------------------------------
                   int Consumer_c::consume(Queue_c &buffur) 
                   { 
                  goods=buffur.DeQueue(); 
                  cout<<"Consume "<<goods<<" has been killed"<<endl; 
                  return OK; 
                   } 
                  /*********************************************************************/


                  10楼2005-10-19 15:16
                  回复
                    • 218.56.138.*
                    #include<iostream.h> 

                     #define QueueMax 5 
                     #define ERROR 0 
                     #define OK 1 
                     #define SHOW buffur.ShowAll(); 

                     typedef int ElemType; 

                     ElemType goods;
                     //head define.................... 
                    /*****************************************************************************************/ 
                     class Queue_c 
                     { 

                     ElemType Q[QueueMax]; 
                     ElemType Queue_c_temp; 
                     int front,rear; 

                     public: 
                     //basic information of the class Queue_c 
                     void ZeroQueue(); 
                     int QFull(); 
                     int QEmpty();
                     int EnQueue(ElemType e);
                     ElemType DeQueue();
                     int GetNumber();
                     void ShowAll();

                     };
                     //define of the class Queue_c...........................
                     //===================================================================
                    class Producer_c
                     {
                     public:
                     ElemType goods;
                     int produce(Queue_c &buffur);
                     };
                     //===================================================================
                    class Consumer_c
                     {
                     ElemType goods;
                     public:
                     int consume(Queue_c &buffur);
                     };
                     //difine of class Consumer_c

                    /******************************************************************************************
                    ******************************************************************************************/
                     void main()
                     {
                     Queue_c buffur;
                     Producer_c producer;
                     Consumer_c consumer;
                     int judge=1;
                     buffur.ZeroQueue();
                     cout<<"===================="<<endl;
                     SHOW


                    while(1)
                     { 

                     judge%=2;
                     if(1==judge)producer.produce(buffur);
                     if(0==judge)consumer.consume(buffur);
                     cout<<"============="<<endl;
                     cout<<"=1 produce ="<<endl;
                     cout<<"=2 consume ="<<endl;
                     cout<<"=others exit="<<endl;
                     cout<<"============="<<endl;
                     cin>>judge;

                     if(1==judge)
                     {

                     if(buffur.QFull())
                     {judge=2;continue; }
                     cout<<"you pressed 1,product"<<endl;

                     }//if 1

                     if(2==judge)
                     {

                     if(buffur.QEmpty()){judge=1;continue;}
                     cout<<"you pressed 2,consume"<<endl;

                     }// if 2

                     if(1!=judge&&2!=judge)break;

                     }//while 

                    SHOW

                    }
                    /*****************************************************************************************
                    ******************************************************************************************/
                     void Queue_c::ZeroQueue()
                     {
                     int i;
                     for(i=0;i<QueueMax;i++)Q[i]=0;
                     rear=front=0;
                     }
                     //zzzzzzzzzzzzzzzz
                     int Queue_c::QFull()
                     {
                     if((rear+1)%QueueMax==front)
                     {cout<<"Queue is full"<<endl;
                     return OK;
                     }
                     else return ERROR;
                     }

                     //QFull...................
                     int Queue_c::QEmpty()
                     {
                     if(rear==front)
                     { 
                     cout<<"Queue is Empty"<<endl; 
                     return OK;
                     } 
                     else return ERROR; 
                     }
                     //QEmpty.......................... 

                     int Queue_c::EnQueue(ElemType e) 
                     { 
                     if(QFull())return ERROR; 
                     Q[rear]=e; 
                     rear=(rear+1)%QueueMax;
                     return OK; 
                     } 


                     //EnQueue......................... 

                     ElemType Queue_c::DeQueue() 
                     { 
                     if(QEmpty())return ERROR; 
                     Queue_c_temp=Q[front]; 
                     Q[front]=0; 
                     front=(front+1)%QueueMax; 
                     return Queue_c_temp;
                     } 
                     //DeQueue.......................
                     int Queue_c::GetNumber()
                     {int i;
                     i=((rear-front+QueueMax)%QueueMax);
                     return i;
                     }


                     //GetNumber.......................
                     void Queue_c::ShowAll()
                     {int i;
                     for(i=0;i<QueueMax;i++)
                     cout<<Q[i]<<" ";
                     cout<<endl;
                     }

                     //ShowAll.........................
                    /*******************************************************************/
                     int Producer_c::produce(Queue_c &buffur)
                     {

                     if(buffur.QFull())
                     {cout<<"Produce:please input a number"<<endl;
                     cin>>goods;
                     buffur.EnQueue(goods);
                     return OK;
                     }//produce_B..........................
                     }
                     //class Producer_c
                    /********************************************************************/
                     int Consumer_c::consume(Queue_c &buffur)
                     {
                     goods=buffur.DeQueue();
                     cout<<"Consume "<<goods<<" has been killed"<<endl;
                     return OK;
                     }
                    /*********************************************************************/


                    11楼2005-10-19 15:36
                    回复
                      • 218.56.138.*
                      #include<iostream.h> 

                       #define QueueMax 5 
                       #define ERROR 0 
                       #define OK 1 
                       #define SHOW buffur.ShowAll(); 

                       typedef int ElemType; 

                       ElemType goods;
                       //head define.................... 
                      /*****************************************************************************************/ 
                       class Queue_c 
                       { 

                       ElemType Q[QueueMax]; 
                       ElemType Queue_c_temp; 
                       int front,rear; 

                       public: 
                       //basic information of the class Queue_c 
                       void ZeroQueue(); 
                       int QFull(); 
                       int QEmpty();
                       int EnQueue(ElemType e);
                       ElemType DeQueue();
                       int GetNumber();
                       void ShowAll();

                       };
                       //define of the class Queue_c...........................
                       //===================================================================
                      class Producer_c
                       {
                       public:
                       ElemType goods;
                       int produce(Queue_c &buffur);
                       };
                       //===================================================================
                      class Consumer_c
                       {
                       ElemType goods;
                       public:
                       int consume(Queue_c &buffur);
                       };
                       //difine of class Consumer_c

                      /******************************************************************************************
                      ******************************************************************************************/
                       void main()
                       {
                       Queue_c buffur;
                       Producer_c producer;
                       Consumer_c consumer;
                       int judge=1;
                       buffur.ZeroQueue();
                       cout<<"===================="<<endl;
                       SHOW


                      while(1)
                       { 
                       if(1==judge)producer.produce(buffur);
                       if(0==judge)consumer.consume(buffur);
                       cout<<"============="<<endl;
                       cout<<"=1 produce ="<<endl;
                       cout<<"=2 consume ="<<endl;
                       cout<<"=others exit="<<endl;
                       cout<<"============="<<endl;
                       cin>>judge;

                       if(1==judge)
                       {

                       if(buffur.QFull())
                       {judge=2;continue; }
                       cout<<"you pressed 1,product"<<endl;

                       }//if 1

                       if(2==judge)
                       {

                       if(buffur.QEmpty()){judge=1;continue;}
                       cout<<"you pressed 2,consume"<<endl;

                       }// if 2

                       if(1!=judge&&2!=judge)break;

                       }//while 

                      SHOW

                      }
                      /*****************************************************************************************
                      ******************************************************************************************/
                       void Queue_c::ZeroQueue()
                       {
                       int i;
                       for(i=0;i<QueueMax;i++)Q[i]=0;
                       rear=front=0;
                       }
                       //zzzzzzzzzzzzzzzz
                       int Queue_c::QFull()
                       {
                       if((rear+1)%QueueMax==front)
                       {cout<<"Queue is full"<<endl;
                       return OK;
                       }
                       else return ERROR;
                       }

                       //QFull...................
                       int Queue_c::QEmpty()
                       {
                       if(rear==front)
                       { 
                       cout<<"Queue is Empty"<<endl; 
                       return OK;
                       } 
                       else return ERROR; 
                       }
                       //QEmpty.......................... 

                       int Queue_c::EnQueue(ElemType e) 
                       { 
                       if(QFull())return ERROR; 
                       Q[rear]=e; 
                       rear=(rear+1)%QueueMax;
                       return OK; 
                       } 


                       //EnQueue......................... 

                       ElemType Queue_c::DeQueue() 
                       { 
                       if(QEmpty())return ERROR; 
                       Queue_c_temp=Q[front]; 
                       Q[front]=0; 
                       front=(front+1)%QueueMax; 
                       return Queue_c_temp;
                       } 
                       //DeQueue.......................
                       int Queue_c::GetNumber()
                       {int i;
                       i=((rear-front+QueueMax)%QueueMax);
                       return i;
                       }


                       //GetNumber.......................
                       void Queue_c::ShowAll()
                       {int i;
                       for(i=0;i<QueueMax;i++)
                       cout<<Q[i]<<" ";
                       cout<<endl;
                       }

                       //ShowAll.........................
                      /*******************************************************************/
                       int Producer_c::produce(Queue_c &buffur)
                       {
                       cout<<"Produce:please input a number"<<endl;
                       cin>>goods;
                       buffur.EnQueue(goods);
                       return OK;
                       
                       }
                      /********************************************************************/
                       int Consumer_c::consume(Queue_c &buffur)
                       {
                       goods=buffur.DeQueue();
                       cout<<"Consume "<<goods<<" has been killed"<<endl;
                       return OK;
                       }
                      /*********************************************************************/


                      12楼2005-10-19 15:40
                      回复
                        • 218.56.138.*
                        #include<iostream.h> 

                         #define QueueMax 5 
                         #define ERROR 0 
                         #define OK 1 
                         #define SHOW buffur.ShowAll(); 

                         typedef int ElemType; 

                         ElemType goods;
                         //head define.................... 
                        /*****************************************************************************************/ 
                         class Queue_c 
                         { 

                         ElemType Q[QueueMax]; 
                         ElemType Queue_c_temp; 
                         int front,rear; 

                         public: 
                         //basic information of the class Queue_c 
                         void ZeroQueue(); 
                         int QFull(); 
                         int QEmpty();
                         int EnQueue(ElemType e);
                         ElemType DeQueue();
                         int GetNumber();
                         void ShowAll();

                         };
                         //define of the class Queue_c...........................
                         //===================================================================
                        class Producer_c
                         {
                         public:
                         ElemType goods;
                         int produce(Queue_c &buffur);
                         };
                         //===================================================================
                        class Consumer_c
                         {
                         ElemType goods;
                         public:
                         int consume(Queue_c &buffur);
                         };
                         //difine of class Consumer_c

                        /******************************************************************************************
                        ******************************************************************************************/
                         void main()
                         {
                         Queue_c buffur;
                         Producer_c producer;
                         Consumer_c consumer;
                         int judge=1;
                         buffur.ZeroQueue();
                         cout<<"===================="<<endl;
                         SHOW


                        while(1)
                         {
                         if(1==judge)producer.produce(buffur);
                         if(2==judge)consumer.consume(buffur);
                         cout<<"============="<<endl;
                         cout<<"=1 produce ="<<endl;
                         cout<<"=2 consume ="<<endl;
                         cout<<"=others exit="<<endl;
                         cout<<"============="<<endl;
                         cin>>judge;

                         if(1==judge)
                         {

                         if(buffur.QFull())
                        {judge=2;continue; }
                         cout<<"you pressed 1,product"<<endl;

                        }//if 1

                         if(2==judge)
                         {

                         if(buffur.QEmpty()){judge=1;continue;}
                         cout<<"you pressed 2,consume"<<endl;

                         }// if 2

                         if(1!=judge&&2!=judge)break;
                         SHOW

                         }//while

                        SHOW

                        }
                        /*****************************************************************************************
                        ******************************************************************************************/
                         void Queue_c::ZeroQueue()
                         {
                         int i;
                         for(i=0;i<QueueMax;i++)Q[i]=0;
                         rear=front=0;
                         }
                         //zzzzzzzzzzzzzzzz
                         int Queue_c::QFull()
                         {
                         if((rear+1)%QueueMax==front)
                         {cout<<"Queue is full"<<endl;
                         return OK;
                         }
                         else return ERROR;
                         }

                         //QFull...................
                         int Queue_c::QEmpty()
                         {
                         if(rear==front)
                         {
                         cout<<"Queue is Empty"<<endl;
                         return OK;
                         }
                         else return ERROR;
                         }
                         //QEmpty..........................

                         int Queue_c::EnQueue(ElemType e)
                         {
                         if(QFull())return ERROR;
                         Q[rear]=e;
                         rear=(rear+1)%QueueMax;
                         return OK;
                         }


                         //EnQueue.........................

                         ElemType Queue_c::DeQueue()
                         {
                         if(QEmpty())return ERROR;
                         Queue_c_temp=Q[front];
                         Q[front]=0;
                         front=(front+1)%QueueMax;
                         return Queue_c_temp;
                         }
                         //DeQueue.......................
                         int Queue_c::GetNumber()
                         {int i;
                         i=((rear-front+QueueMax)%QueueMax);
                         return i;
                         }


                         //GetNumber.......................
                         void Queue_c::ShowAll()
                         {int i;
                         for(i=0;i<QueueMax;i++)
                         cout<<Q[i]<<" ";
                         cout<<endl;
                         }

                         //ShowAll.........................
                        /*******************************************************************/
                         int Producer_c::produce(Queue_c &buffur)
                         {
                         cout<<"Produce:please input a number"<<endl;
                         cin>>goods;
                         buffur.EnQueue(goods);
                         return OK;

                         }
                        /********************************************************************/
                         int Consumer_c::consume(Queue_c &buffur)
                         {
                         goods=buffur.DeQueue();
                         cout<<"Consume "<<goods<<" has been killed"<<endl;
                         return OK;
                         }
                        /*********************************************************************/


                        13楼2005-10-19 15:46
                        回复