您的位置:首页 > 其它

链队列

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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: