首页 > 其他 > 详细

队列的顺序储存

时间:2017-02-25 12:04:57      阅读:201      评论:0      收藏:0      [点我收藏+]
 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 }

技术分享

 

队列的顺序储存

原文:http://www.cnblogs.com/zhengzhe/p/6441188.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!