链队列的基本操作

#include <stdio.h>	
#include<stdlib.h>
typedef struct node
{
	char data;
	struct node *next;
}QNode;
typedef  struct
{
	QNode *front, *rear;
}LQueue;
void Init_LQueue(LQueue **q)
{
	QNode *p;
	*q = (LQueue*)malloc(sizeof(LQueue));
	p = (QNode*)malloc(sizeof(QNode));
	p->next = NULL;
	(*q)->front = p;
	(*q)->rear = p;
}
int Empty_LQueue(LQueue *q)
{
	if (q->front == q->rear)
	{
		return 1;

	}
	else
	{
		return 0;
	}
	
}
void In_LQueue(LQueue *q, char x)
{
	QNode *p;
	p = (QNode *)malloc(sizeof(QNode));
	p->data = x;
	p->next = NULL;
	q->rear->next = p;
	q->rear = p;
}
void Out_LQueue(LQueue *q, char *x)
{
	QNode *p;
	if (Empty_LQueue(q))
		printf("kong\n");
	else
	{
		p = q->front->next;
		q->front->next = p->next;
		*x = p->data;
		free(p);
	}
	if (q->front->next==NULL)
	{
		q->front = q->rear;
	}
}
void print(LQueue *q)
{
	QNode *p;
	p = q->front->next;
	while (p!=NULL)
	{
		printf("%-2c", p->data);
		p = p->next;
	}
	printf("\n");
}
void	main(void)
{
	LQueue *q;
	char x, *y = &x;
	Init_LQueue(&q);
	if (Empty_LQueue(q))
		printf("kong\n");
	printf("input string\n");
	scanf("%c", &x);
	while (x!='\n')
	{
		In_LQueue(q, x);
		scanf("%c", &x);
	}
	print(q);
	Out_LQueue(q, y);
	printf("out%c\n", *y);
	print(q);
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值