순환 대기열 M
                                            
 11341 단어  대열
                    
 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #define TRUE 1
 4 #define FALSE 0
 5 #define ERROR 0
 6 #define OK 1
 7 #define OVERFLOW -2
 8 #define MAXQSIZE 100
 9 #define LEN sizeof(QElemType)
10 typedef int Status;
11 typedef int QElemType;
12 typedef struct
13 {
14     QElemType *base;
15     int front;
16     int rear;
17 }SqQueue;
18 Status InitQueue(SqQueue &Q)// .
19 {
20     Q.base=(QElemType *)malloc(LEN);
21     if(!Q.base) exit(FALSE);
22     Q.front=Q.rear=0;
23     return OK;
24 }
25 int QueueLength(SqQueue Q)
26 {
27     return (Q.rear-Q.front+MAXQSIZE)%MAXQSIZE;
28 }
29 Status EnQueue(SqQueue &Q,QElemType e)// , e
30 {
31     if((Q.rear+1)%MAXQSIZE==Q.front) return OVERFLOW;
32     Q.base[Q.rear]=e;
33     Q.rear=(Q.rear+1)%MAXQSIZE;
34     return OK;
35 }
36 Status DeQueue(SqQueue &Q,QElemType &e)// , , e
37 {
38       if(Q.front==Q.rear) return ERROR;
39        e=Q.base[Q.front];
40        Q.front=(Q.front+1)%MAXQSIZE;
41        return OK;
42 }
43 Status PrintQueue(SqQueue Q)// 
44 {
45     QElemType e;
46     int n=QueueLength(Q);
47     printf(" :");
48     printf("
********************
");
49     while(n--)
50     {
51         DeQueue(Q,e);
52         printf("%d ",e);
53     }
54     printf("
********************
");
55     return OK;
56 }
57 Status ClearQueue(SqQueue &Q)// 
58 {
59     Q.front=Q.rear=0;
60     return OK;
61 }        
62 Status main()
63 {
64     SqQueue Q;
65     QElemType e; 
66     InitQueue(Q);
67     int n;
68     puts(" :");
69     scanf("%d",&n);
70     puts(" :");
71     while(n--)
72     {
73         scanf("%d",&e);
74         EnQueue(Q,e);
75     }
76     PrintQueue(Q);
77     puts(" :");
78     scanf("%d",&e);
79     EnQueue(Q,e);
80     PrintQueue(Q);
81     puts(" :");
82     DeQueue(Q,e);
83     printf(" :%d
",e);
84     PrintQueue(Q);
85     ClearQueue(Q);
86     system("pause");
87     return OK;
88 }
                이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
간단한 애니메이션 대기열 모델텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.