链队列
2015-11-07 20:17
337 查看
#include<stdio.h>
#include<stdlib.h>
#define TRUE 1;
#define FALSE 0;
typedef struct node
{
int date;
struct node *next;
}LQ;
typedef struct
{
LQ *front;
LQ *rear;
}Lq;
void inqu(Lq *Q)//初始化
{
Q->front=(LQ *)malloc(sizeof(LQ));
if(Q->front!=NULL)
{
Q->rear=Q->front;
Q->front->next=NULL;
}
}
void enter(Lq *Q)//进
{
int x;
printf("请输入x的值:");
scanf("%d",&x);
LQ *p;
while(x!=0)
{
p=(LQ *)malloc(sizeof(LQ));
p->date=x;
Q->rear->next=p;
Q->rear=p;
scanf("%d",&x);
}
p->next=NULL;
}
void delet(Lq *Q)//出
{
LQ *p;
if(Q->front==Q->rear)
printf("出栈错误!!!");
p=Q->front->next;
Q->front->next=p->next;
if(Q->rear==p)
Q->rear=Q->front;
}
void prin(Lq *Q)
{
LQ *s=Q->front->next;
while(s!=NULL)
{
printf("%d ",s->date);
s=s->next;
}
printf("\n");
}
int main()
{
Lq Q;
inqu(&Q);
enter(&Q);
delet(&Q);
prin(&Q);
return 0;
}
#include<stdlib.h>
#define TRUE 1;
#define FALSE 0;
typedef struct node
{
int date;
struct node *next;
}LQ;
typedef struct
{
LQ *front;
LQ *rear;
}Lq;
void inqu(Lq *Q)//初始化
{
Q->front=(LQ *)malloc(sizeof(LQ));
if(Q->front!=NULL)
{
Q->rear=Q->front;
Q->front->next=NULL;
}
}
void enter(Lq *Q)//进
{
int x;
printf("请输入x的值:");
scanf("%d",&x);
LQ *p;
while(x!=0)
{
p=(LQ *)malloc(sizeof(LQ));
p->date=x;
Q->rear->next=p;
Q->rear=p;
scanf("%d",&x);
}
p->next=NULL;
}
void delet(Lq *Q)//出
{
LQ *p;
if(Q->front==Q->rear)
printf("出栈错误!!!");
p=Q->front->next;
Q->front->next=p->next;
if(Q->rear==p)
Q->rear=Q->front;
}
void prin(Lq *Q)
{
LQ *s=Q->front->next;
while(s!=NULL)
{
printf("%d ",s->date);
s=s->next;
}
printf("\n");
}
int main()
{
Lq Q;
inqu(&Q);
enter(&Q);
delet(&Q);
prin(&Q);
return 0;
}
相关文章推荐
- soj 1162: I-Keyboard(dp + 记忆化搜索)
- 技术沟通者的自我修养
- 【规律】Gym 100739L Many recursions
- Target/Action 设计模式
- Viewpager以及ViewPagerIndicator的相关使用
- Haoop , Spark安装实例教程--Spark安装
- 面试
- sessionFactory为空之spring依赖注入
- javaweb学习总结(四)——Http协议
- 双向链表
- 循环链表
- MST:Roadblocks(POJ 3255)
- 物联网系统——远征军的战略图
- doxygen中注释,内嵌dot, msc的例子
- 达内学习日志Day51:为登录操作添加拦截器
- 在Ubuntu 14.04上编译Android源码
- CodeForces 131D Subway [tarjan+最短路]
- classpath、path、JAVA_HOME的作用(转)
- 仿站的流程
- hdfs常用API和putMerge功能实现