日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

这份代码是不是应该有BUG!!

發布時間:2023/12/10 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 这份代码是不是应该有BUG!! 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

為什么80%的碼農都做不了架構師?>>> ??

#include"stdio.h"
#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多個吧,我反正是沒有找出來,基礎太差了,╮(╯▽╰)╭,哪位大神看下這智商捉急的代碼吧。

轉載于:https://my.oschina.net/vold/blog/178667

總結

以上是生活随笔為你收集整理的这份代码是不是应该有BUG!!的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。