Simple simulation of banking business queue

From , 5 Years ago, written in C++, viewed 279 times.
URL https://pastebin.vip/view/c5b2cebf
  1. #include<iostream>
  2. using namespace std;
  3. #define MAXSIZE 1000
  4. typedef int QElemType;
  5. typedef struct
  6. {
  7.     QElemType *base;
  8.     int front;
  9.     int rear;
  10. }SqQueue;
  11. void InitQueue(SqQueue &Q)
  12. {
  13.     Q.base=new QElemType[MAXSIZE];
  14.     Q.front=Q.rear=0;
  15. }
  16. void CreateSqQueue(SqQueue &Q1,SqQueue &Q2,int sum)
  17. {
  18.     int a;
  19.     for(int i=0;i<sum;i++)
  20.     {
  21.         cin>>a;
  22.         if(a%2)
  23.         {
  24.             Q1.base[Q1.rear]=a;
  25.             Q1.rear=(Q1.rear+1)%MAXSIZE;
  26.         }
  27.         else
  28.         {
  29.             Q2.base[Q2.rear]=a;
  30.             Q2.rear=(Q2.rear+1)%MAXSIZE;
  31.         }
  32.     }
  33. }
  34. void PrintfSqQueue(SqQueue &Q1,SqQueue &Q2,SqQueue Q3,int s)
  35. {
  36.     int a=1;
  37.     while((Q1.front!=Q1.rear)||(Q2.front!=Q2.rear))
  38.     {
  39.         if((a==1)||(a==2))
  40.         {
  41.             if(Q1.front!=Q1.rear)
  42.             {
  43.                 Q3.base[Q3.rear]=Q1.base[Q1.front];
  44.                 Q3.rear=(Q3.rear+1)%MAXSIZE;
  45.                 Q1.front=(Q1.front+1)%MAXSIZE;
  46.             }
  47.         }
  48.         else
  49.         {
  50.             if(Q2.front!=Q2.rear)
  51.             {
  52.                 Q3.base[Q3.rear]=Q2.base[Q2.front];
  53.                 Q3.rear=(Q3.rear+1)%MAXSIZE;
  54.                 Q2.front=(Q2.front+1)%MAXSIZE;
  55.             }
  56.         }
  57.         a++;
  58.         if(a>3)
  59.             a=1;
  60.     }
  61.     cout<<Q3.base[Q3.front];
  62.     Q3.front=(Q3.front+1)%MAXSIZE;
  63.     for(int i=0;i<s-1;i++)
  64.     {
  65.         cout<<" "<<Q3.base[Q3.front];
  66.         Q3.front=(Q3.front+1)%MAXSIZE;
  67.     }
  68. }
  69. int main ()
  70. {
  71.     int sum;
  72.     SqQueue Q1,Q2,Q3;
  73.     InitQueue(Q1);
  74.     InitQueue(Q2);
  75.     InitQueue(Q3);
  76.     cin>>sum;
  77.     if(sum)
  78.     {
  79.         CreateSqQueue(Q1,Q2,sum);
  80.         PrintfSqQueue(Q1,Q2,Q3,sum);
  81.     }
  82.     else
  83.         cout<<"0"<<endl;
  84.     return 0;
  85. }
  86.  

Reply to "Simple simulation of banking business queue"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website