• 队列的顺序储存


     1 #include<iostream>
     2 #include<ctime>
     3 using namespace std;
     4 
     5 #define MAXSIZE 10
     6 struct quene
     7 {
     8     int count;
     9     int number[MAXSIZE];
    10     int front;
    11     int end;
    12 };
    13 
    14 
    15 void inquene(quene *s,int n)
    16 {
    17     if (s->count == MAXSIZE)
    18         exit(1);
    19     s->count++;
    20     s->number[s->end++] = n;
    21 }
    22 
    23 
    24 int dequene(quene *s)
    25 {
    26     if (s->count != 0)
    27     {
    28         int t = s->number[s->front++];
    29         return t;
    30     }
    31     else return -1;
    32 }
    33 
    34 
    35 
    36 void createquene(quene *s,int x)
    37 {
    38     srand(time(0));
    39     if (x > MAXSIZE)
    40         exit(1);
    41     else
    42     {
    43         for (int i = 1; i <= x; i++)
    44         {
    45             inquene(s, rand() % 100 + 1);
    46             //cout << s->number[i - 1] << endl;
    47         }
    48     }
    49 }
    50 
    51 void main()
    52 {
    53     quene *s=new quene;
    54     s->front = 0;
    55     s->end = 0;
    56     s->count = 0;
    57     createquene(s, 10);
    58     for (int i = 1; i <= 10; i++)
    59         cout << dequene(s) << endl;
    60 }

  • 相关阅读:
    数据库期末考试复习
    函数 初识
    文件操作
    深浅copy 和 集合
    数据编码补充
    字典的增删改查和嵌套
    面试题 和 python 2与3的期区别
    英文练习
    初识数据类型
    测试基础-系统测试(2)
  • 原文地址:https://www.cnblogs.com/zhengzhe/p/6441188.html
Copyright © 2020-2023  润新知