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 }