为什么80%的码农都做不了架构师?>>>
#include"stdlib.h"
#include"math.h"
#include"io.h"
#include"time.h"
#define OK 1
#define ERROR 0
#define TRUE 1
#define FALSE 0
#define MAXSIZE 20
typedef int Status;
typedef int QElemType;
typedef struct{
QElemtype data[MAXSIZE];
int front;
int rear;
}SqQueue;
Status visit(QElemType c)
{
printf("%d", c);
return OK;
}
Status InitQueue(SqQueue *Q)
{
Q->front = 0;
Q->rear = 0;
return OK;
}//初始化队列
Status ClearQueue(SqQueue *Q)
{
Q->front = Q->rear = 0;
return OK;
}//清空队列
Status QueueEmpty(SqQueue Q)
{
if (Q.front = Q.rear)
return TRUE;
else
return FALSE;
}
int QueueLength(SqQueue Q)
{
return (Q.rear - Q.front + MAXSIZE) % MAXSIZE;
}
Status GetHead(SqQueue Q, QElemType *e)
{
if (Q.rear == Q.front)
return ERROR;
else
*e = Q.data[Q.front];
return OK;
}//用e返回Q的队头元素
Status EnQueue(SqQueue *Q, QElemType e)
{
if ((Q->rear + 1) % MAXSIZE == Q->front)
return ERROR;
Q->data[Q->rear] = e;
Q->rear = (Q->rear + 1) % MAXSIZE;
return OK;
}//插入元素e
Status DeQueue(SqQueue *Q, QElemType *e)
{
if (Q->front == Q->rear)
return ERROR;
*e = Q->data[Q->front];
Q->front = (Q->front + 1) % MAXSIZE;
return OK;
}
Status QueueTraverse(SqQueue Q)
{
int i;
i = Q.front;
while ((i + Q.front) != Q.rear)
{
visit(Q.data[i]);
i = (i + 1) % MAXSIZE;
}
printf("\n");
return OK;
}//输出Q中的所有元素
int main()
{
Status j;
int i = 0, 1;
QElemType d;
SqQueue Q;
InitQueue(&Q);
printf("队列空否(1,是;0,否)",QueueEmpty(Q));
while (i<MAXSIZE - 1)
{
d = i + 100;
if (d = = -1)
break;
i++;
EnQueue(&Q, d);
}
printf("队列长度为:%d\n",QueueLength(Q));
for (l = 1; l <= MAXSIZE; l++)
{
DeQueue(&Q, &d);
printf("要删除的元素是:%d,要插入的元素是:%d", d, l + 1000);
d = l + 1000;
EnQueue(&Q, d);
}
l = QueueLength(Q);
printf("现在队列中的元素为:");
QueueTraverse(Q);
printf("共向队列中插入了 %d个元素",i + MAXSIZE);
if (l - 2>0)
printf("现在由队头删除 %d 个元素",l - 2);
while (QueueLength(Q)>2)
{
DeQueue(&Q, &d);
printf("删除的元素为:%d\n", d);
}
j = GetHead(Q, &d);
if (j)
printf("现在队头元素为:%d\n", d);
ClearQueue(&Q);
printf("清空队列后, 队列空否?%u(1:空 0:否)\n", QueueEmpty(Q));
return 0;
}
我觉得没有错,但是真的有很多错误,大概40多个吧,我反正是没有找出来,基础太差了,╮(╯▽╰)╭,哪位大神看下这智商捉急的代码吧。