#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);
}