zoukankan      html  css  js  c++  java
  • 3-3 银行业务队列简单模拟

     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 
     4 #define MAXSIZE 1000
     5 #define ERROR -1
     6 
     7  struct Node{
     8     int Customer[MAXSIZE];
     9     int rear;
    10     int front;
    11 };
    12 
    13  typedef struct Node* Queue;
    14 
    15  Queue CreateQueue()
    16  {
    17      Queue Q = (Queue)malloc(sizeof(struct Node));
    18      Q->front = 0;
    19      Q->rear = 0;
    20      return Q;
    21  }
    22 
    23  int IsEmpty(Queue Q)
    24  {
    25      return Q->front == Q->rear;
    26  }
    27 
    28  void AddQ(Queue Q, int X)
    29  {
    30      if ((Q->rear + 1) % MAXSIZE == Q->front)
    31      {
    32          printf("The queue is full!
    ");
    33          return;
    34      }
    35      Q->Customer[Q->rear] = X;
    36      Q->rear = (Q->rear + 1) % MAXSIZE;
    37  }
    38 
    39  int DeleteQ(Queue Q)
    40  {
    41      if (IsEmpty(Q))
    42      {
    43          printf("The queue is empty!
    ");
    44          return ERROR;
    45      }
    46      int elem = Q->Customer[Q->front];
    47      Q->front = (Q->front + 1) % MAXSIZE;
    48      return elem;
    49  }
    50 
    51  int main()
    52  {
    53      int N, X;
    54      int flag = 0;
    55      Queue Q, Q1, Q2;
    56      Q1 = CreateQueue();
    57      Q2 = CreateQueue();
    58      scanf_s("%d", &N);
    59      while (N--)
    60      {
    61          scanf_s("%d", &X);
    62          if (X % 2)
    63             AddQ(Q1, X);
    64          else
    65              AddQ(Q2, X);
    66      }
    67      while (!IsEmpty(Q1) && !IsEmpty(Q2))
    68      {
    69          if (!flag)
    70              flag = 1;
    71          else
    72              printf(" ");
    73          printf("%d", DeleteQ(Q1));
    74          printf(" %d", DeleteQ(Q1));
    75          printf(" %d", DeleteQ(Q2));
    76      }
    77      while (!IsEmpty(Q1))
    78      {
    79          if (!flag)
    80              flag = 1;
    81          else
    82              printf(" ");
    83          printf("%d", DeleteQ(Q1));
    84      }
    85 
    86         
    87      while (!IsEmpty(Q2))
    88      {
    89          if (!flag)
    90              flag = 1;
    91          else
    92              printf(" ");
    93          printf("%d", DeleteQ(Q2));
    94      }
    95     return 0;    
    96  }
  • 相关阅读:
    hdu 1599 floyd 最小环(floyd)
    poj 1328 Radar Installation(贪心)
    poj 2488 A Knight's Journey(dfs)
    hdu 2544 最短路 (dijkstra)
    hdu 2015 偶数求和(水)
    hdu 2063 过山车(二分图最大匹配基础)
    hdu 1052 Tian Ji -- The Horse Racing(贪心)
    hdu 2122 Ice_cream’s world III(最小生成树)
    RabbitMQ中 exchange、route、queue的关系
    Windows安装Rabbitmq
  • 原文地址:https://www.cnblogs.com/hi3254014978/p/9769637.html
Copyright © 2011-2022 走看看