#include "stdio.h"
#define MAXCSIZE 100
typedef int ElemType;
typedef struct
{ ElemType *base;
int front;
int rear;
}cqueue;
void initqueue(cqueue *cq)
{ cq->base=(ElemType *)malloc(MAXCSIZE *sizeof(ElemType));
if(!cq->base) exit(1);
cq->front=cq->rear=0;
}
int enqueue(cqueue *cq,ElemType x)
{ if((cq->rear+1)%MAXCSIZE==cq->front) return 0;
cq->base[cq->rear]=x;
cq->rear=(cq->rear+1)%MAXCSIZE;
return 1;
}
int outqueue(cqueue *cq,ElemType *e)
{ if(cq->front==cq->rear) return 0;
*e=cq->base[cq->front];
cq->front=(cq->front+1)%MAXCSIZE;
return 1;
}
void list(cqueue cq)
{ int i;
i=cq.front;
while(i!=cq.rear)
{ printf("%4d",cq.base[i]);
i=(i+1)%MAXCSIZE;
}
printf("\n");
}
void fun(void)
{ int x;
while(x!=0)
{ if(x>0)
{ if(!enqueue(&cq,x))
{printf("The cycle queue is full!\n");break;}
}
else if(!outqueue(&cq,&x))
{printf("The cycle queue is empty!\n");break;}
scanf("%4d",&x);
}
}
int main()
{ cqueue cq;
ElemType x;
initqueue(&cq);
printf("please input sequences of integers:\n");
scanf("%d",&x);
fun(void);
list(&cq);
getch();
}
这是用循环队列完成从键盘输入一整数序列,若a i>0进队列,a i<0队头元素出队列,=0结束。为什么老是提示Undefined symbol '_main' in module C0S错误信息那?而且运行不了~·