苏嵌项目

学习日志
姓名:潘安琪
日期:2018/9/5
今日学习任务
列的队头队尾,先进先出;链式结构,循环队列
今日任务完成情况

#include <stdio.h>
#include "queue.h"
#include <stdlib.h>

int main()
{
Q queue;
int ret,i;

ret=InitQueue(&queue);//chushihuaduilie
if(ret==FAILURE)//fanhuizhipanduan
{
printf("Init Failure!\n");
exit(1);
}
else if (ret==SUCCESS)
{
printf("Init Success!\n");
}
ret=EmptyQueue(queue);
if (ret==SUCCESS)
{
printf ("queue is empty\n");
}
else if(ret==FAILURE)
{
printf("queue is not empty\n");
}
for (i=0;i<10;i++)
{
ret=EnterQueue(&queue,i+1);
if(ret==FAILURE)
{
printf("enter==success!\n",i+1);
}

else if (ret==SUCCESS)
{
printf("enter %d success!\n",i+1);
}
}
int length=LengthQueue(queue);//huoquduilieyuansu
printf("length is %d\n",length);
ret=GetFront(queue);
if(ret==FAILURE)
{
printf("get front failure!\n");
}
else
{
printf("front is %d\n",ret);
}
for (i=0;i<5;i++)
{
ret=DelQueue(&queue);
if(ret==FAILURE)
{
printf("del Failure!\n");
}
else
{
printf("del %d  Failure!\n",ret);
}
}
length=LengthQueue(queue);
printf("length is %d\n",length);
ret=GetFront(queue);
if(ret==FAILURE)
{
printf("get front failure!\n");
}
else
{
printf("front is %d\n",ret);
}
ret=ClearQueue(&queue);
if(ret==SUCCESS)
{
printf("clear Success !\n");
}
else
{
printf("clear Failure!\n");
}
ret=GetFront(queue);
if(ret==FAILURE)
{
printf("get front failure!\n");
}
else
{
printf("front is %d\n",ret);
}
ret=DestroyQueue(&queue);
if(ret==FAILURE)
{
printf("Destroy failure!\n");
}
else
{
printf("Destroy success!\n");
}
return 0;
}
#include "queue.h"
#include<stdlib.h>

int InitQueue(Q *q)
{
if (NULL==q)//rucanpanduan
{
return FAILURE;
}
q->data=(int*)malloc(sizeof(int)*MAXSIZE);
if (NULL==q->data)
{
return FAILURE;
}
q->front=q->rear=0;
return SUCCESS;

}
int EmptyQueue(Q q)
{
return ((q.front==q.rear) ? SUCCESS:FAILURE);
}
int EnterQueue(Q *q,int e)
{
if (NULL==q)//rucanpanduan
{
return FAILURE;
}
if ((q->rear+1)%MAXSIZE==q->front)
{
return FAILURE;
}
q->data[q->rear]=e;
q->rear=(q->rear+1)%MAXSIZE;

return SUCCESS;
}
int LengthQueue(Q q)
{
int len;
len=(q.rear-q.front+MAXSIZE)%MAXSIZE;

return len;
}
int GetFront(Q q)
{
if (q.front==q.rear)
{
return FAILURE;
}
//fanhuidiyigeyuansu
return q.data[q.front];
}
int DelQueue(Q *q)
{
if (NULL==q)
{
return FAILURE;
}
if (q->rear==q->front)
{
return FAILURE;
}
int e=q->data[q->front];
q->front=(q->front+1)%MAXSIZE;
return e;
}
int ClearQueue(Q *q)
{
if(NULL==q)
{
return FAILURE;
}
q->rear=q->front;
return SUCCESS;
}
int DestroyQueue(Q *q)
{
if(NULL==q)
{
return FAILURE;
}
free(q->data);
return SUCCESS;
}
#ifndef QUEUE_H
#define QUEUE_H

#define MAXSIZE   10
#define SUCCESS   1000
#define FAILURE   1001

struct queue//biaoshiduiliedexinxi
{
int *data;
int front;//duitou
int rear;//duiwei
};
typedef struct queue Q;
int InitQueue(Q *q);
int EnterQueue(Q *q,int e);
int LengthQueue(Q q);
int EmptyQueue(Q q);
int GetFront(Q q);
int DelQueue(Q *q);
int ClearQueue(Q *q);
#endif

链式结构

#include <stdio.h>
#include "queue.h"

int main()
{
Q queue;
int ret,i;
ret =InitQueue(&queue);
if (ret==FAILURE)
{
printf("Init Failure!\n");
}
else if(ret==SUCCESS)
{
printf("Init Success!\n");
}
for (i=0;i<5;i++)
{
ret=EnterQueue(&queue,i+1);
if (ret==FAILURE)
{
printf("enter failure!\n");
}
else if(ret==SUCCESS)
{
printf("enter %d success!\n",i+1);
}
}
int length=LengthQueue(queue);
printf ("length is %d\n",length);

ret=GetFront(queue);
if(FAILURE==ret)
{
printf("get front failure!\n");

}
else
{
printf("front is %d\n",ret);

}
for (i=0;i<3;i++)
{
ret=DelQueue(&queue);
if(ret==FAILURE)
{
printf("Delete Failure!\n");
}
else
{
printf("Delete %d Success!\n",ret);
}
}
ret=ClearQueue(&queue);
if(ret==SUCCESS)
{
printf("clear Success !\n");
}
else
{
printf("clear Failure!\n");
}
ret=DestroyQueue(&queue);
if(ret==FAILURE)
{
printf("Destroy failure!\n");
}
else
{
printf("Destroy success!\n");
}
for (i=0;i<5;i++)
{
ret=EnterQueue(&queue,i+1);
if (ret==FAILURE)
{
printf("enter failure!\n");
}
else if(ret==SUCCESS)
{
printf("enter %d success!\n",i+1);
}
}



return 0;
}
#include <stdlib.h>
#include"queue.h"
int InitQueue(Q *q)
{
Node *p=(Node *)malloc (sizeof(Node));
if(NULL==p)
{
return FAILURE;
}
p->next=NULL;
q->front=q->rear=p;
return SUCCESS;
}
int EnterQueue(Q *q,int e)
{
if (NULL==q)
{
return FAILURE;

}
if(q->rear==NULL)
{
return FAILURE;
}
Node *p=(Node *)malloc (sizeof(Node));
if (NULL==p)
{
return FAILURE;
}
p->data=e;
p->next=NULL;
q->rear->next=p;
q->rear=p;
return SUCCESS;
}
int LengthQueue(Q q)
{
int len=0;
Node *p=q.front->next;
while (p)
{
len++;
p=p->next;
}
return len;
}
int GetFront(Q q)
{
if(q.front==q.rear)
{
return FAILURE;
}
return q.front->next->data;
}
int DelQueue(Q *q)
{
if(NULL==q)
{
return FAILURE;
}
if(q->rear==q->front)
{
return FAILURE;
}
Node *p=q->front->next;
int e=p->data;
q->front->next=p->next;
free(p);
if(q->rear==p)
{
q->rear=q->front;
}
return e;
}
int ClearQueue(Q *q)
{
if(NULL==q)
{
return FAILURE;
}

if(q->rear=q->front);
{
return SUCCESS;
}
Node *p=q->front->next;
while(p)
{
q->front->next=p->next;
free(p);
p=q->front->next;
}
q->rear=q->front;
return SUCCESS;
}
int DestroyQueue(Q *q)
{
if(NULL==q)
{
return FAILURE;
}
free(q->front);//huo  free(q->rear);
return SUCCESS;
}

ifndef QUEUE_H

define QUEUE_H

define SUCCESS 1000

define FAILURE 1001

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

struct queue
{
Node *front;
Node *rear;
};
typedef struct queue Q;
int InitQueue(Q *q);
int EnterQueue(Q *q,int e);
int GetFront(Q q);
int DelQueue(Q *q);
int ClearQueue(Q *q);
int DestroyQueue(Q *q);
#endif
今日未解决的问题
理解不够,粗心
自我评价
今天又勉强能更上节奏,明天希望也可以








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值