zoukankan      html  css  js  c++  java
  • 循环队列(弥补队列顺序储存的不足)

     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->end = (s->end + 1) % MAXSIZE;//不同于顺序储存
    21     s->number[s->end] = n;
    22 }
    23 
    24 
    25 int dequene(quene *s)//不同于顺序储存
    26 {
    27     if (s->count != 0)
    28     {
    29         s->front = (s->front + 1) % MAXSIZE;
    30         int t = s->number[s->front];
    31         return t;
    32     }
    33     else return -1;
    34 }
    35 
    36 
    37 
    38 void createquene(quene *s, int x)
    39 {
    40     srand(time(0));
    41     if (x > MAXSIZE)
    42         exit(1);
    43     else
    44     {
    45         for (int i = 1; i <= x; i++)
    46         {
    47             inquene(s, rand() % 100 + 1);
    48             //cout << s->number[i - 1] << endl;
    49         }
    50     }
    51 }
    52 
    53 void main()
    54 {
    55     quene *s = new quene;
    56     s->front = 0;
    57     s->end = 0;
    58     s->count = 0;
    59     createquene(s, 10);
    60     for (int i = 1; i <= 10; i++)
    61         cout << dequene(s) << endl;
    62 }

  • 相关阅读:
    Python 初识爬虫-**机场出港业务
    Python 基础学习之字典
    Python 基础学习之if语句
    初识 超级账本
    搭建element-ui Vue结构
    回归
    Gin框架body参数获取
    log4go折腾
    go获取当前执行的位置程序
    mybatis generator 整合lombok
  • 原文地址:https://www.cnblogs.com/zhengzhe/p/6441229.html
Copyright © 2011-2022 走看看