栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

这是一个存在大BUG的队列

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

这是一个存在大BUG的队列

include include

typedef struct node{
char data;
struct node *next;
}Node;

typedef struct{
Node front;
Node rear;
}Queue;

//初始化
void Init(Queue *Q)
{
Q->front =NULL;
Q->rear =NULL;

}

//判断队列空
int IsEmpty(Queue *Q)
{

return Q->front==NULL;

}
//入队·

int EnQueue(Queue Q ,char x)
{
Node p=(Node*)malloc(sizeof(Node));
p->data=x;
p->next=NULL;
//printf("rightn");
if(IsEmpty(Q))
{
Q->front=p;
Q->rear=p;
}
else{
Q->rear->next=p;
Q->rear=p;
}
return 1;

}

char OutQueue(Queue *Q)
{

Node *p;
char ch;
if(IsEmpty(Q))
{
    printf("IsEmpty==%dn",IsEmpty(Q));
    printf("The Queue is NULL,you can not out the Queue!n");
}

else if(Q->rear==Q->front)
{
    p=Q->front;
    ch =p->data;
    Q->front=NULL;
    Q->rear=NULL;

    free(p);
}

else{

    p=Q->front;
    Q->front=p->next;

    ch =p->data;
    free(p);

}

Q->rear->next=p;
Q->rear=p;

return 1;

}

void PrintQueue(Queue *Q)
{
printf("rightn");
while(Q->front)
{
printf("%cn",Q->front->data);
Q->front=Q->front->next;
}

}

int main()
{
Queue Q;
printf("Now,we will execute the EnQueue!n");
Init(&Q);
EnQueue(&Q,'a');
EnQueue(&Q,'b');
EnQueue(&Q,'c');
EnQueue(&Q,'d');
EnQueue(&Q,'e');
PrintQueue(&Q);
printf("Now,we will execute the OutQueue!n");
OutQueue(&Q );
PrintQueue(&Q);
//for(;;);

return 0;

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/233681.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号