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  }
  • 相关阅读:
    swift--使用URLSession异步加载图片
    swift--浮点数转换成整数(四舍五入/直接截断)
    swift--环形进度条(UIActivityIndicatorView)的用法
    swift--Timer实现定时器功能,每个一段时间执行具体函数,可以重复,也可以只执行一次
    HTML节点树
    网页的结构
    网页的组成
    HTTP 请求过程
    HTTP 基础术语
    《投资最重要的事》
  • 原文地址:https://www.cnblogs.com/hi3254014978/p/9769637.html
Copyright © 2011-2022 走看看