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 }

 

posted on 2017-02-25 10:52  郑哲  阅读(145)  评论(0编辑  收藏  举报