#ifndef STATUS_H
#define STATUS_H
#define OK 1
#define ERROR 0
#define FALSE -1
#define TRUE 1
typedef int ElemType;
typedef int Status;
#endif
#ifndef STACK_H
#define STACK_H
#include "status.h"
#include <stdio.h>
#define MAXSIZE 20
typedef struct {
ElemType *base;
int front;
int rear;
int length;
}DL;
Status InitDL(DL *d);
Status Push(DL *d,ElemType *e);
Status Pop(DL *d,ElemType *e);
Status IsEmpty(DL *d);
Status Visit(DL*d);
#endif
```cpp
#include "status.h"
#include <stdio.h>
#include "stack.h"
Status InitDL(DL *d){
d->base=(ElemType*)malloc(MAXSIZE*sizeof(ElemType));
d->front=0;
d->rear=0;
return OK;
}
Status Push(DL *d,ElemType *e){
if ((d->rear+1)%MAXSIZE==d->front){
return ERROR;
}
d->base[d->rear] = *e;
d->rear = (d->rear + 1)%MAXSIZE;
return OK;
}
Status Pop(DL *d,ElemType *e){
if(d->front ==d->rear){
return ERROR;
}
*e=d->base[d->front];
d->front=(d->front+1)%MAXSIZE;
return OK;
}
Status IsEmpty(DL *d){
if(d->front == d->rear)
return TRUE;
else
return FALSE;
}
```cpp
#include <stdio.h>
#include "stack.h"
int main(){
DL dl;
DL *d=&dl;
ElemType e;
int n,i,t;
InitDL(d);
printf("头指针指向的下标为 :%d\n",d->front);
printf("尾指针指向的下标为 :%d\n",d->rear);
printf("请输入插入的个数:");
scanf("%d",&n);
for(i=1;i<=n;i++){
printf("你输入的第%d个数为",i);
scanf("%d",&e);
Push(d,&e);
}
t=Push(d,&e);
if(t==OK)
printf("入队成功\n");
else
printf("入队错误\n");
t=IsEmpty(d);
if(t==TRUE)
printf("队列为空\n");
else
printf("队列不为空\n");
t=Pop(d,&e);
if(t==OK){
printf("队列头元素为:%d",e);
printf("\n队列头下标为:%d\n",d->front);
}
t=IsEmpty(d);
if(t==TRUE)
printf("队列为空\n");
else
printf("队列不为空\n");
}