|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
typedef char ElemType;
typedef struct QNode
{
ElemType data;
struct QNode *next;
}QNode,*QueuePrt;
typedef struct
{
QueuePrt front,rear;
}LinkQueue;
void InitQueue(LinkQueue *q)
{
q->front=(QueuePrt)malloc(sizeof(QNode));
if(!q->front)
exit(0);
q->front->next=NULL;
}
void InsertQueue(LinkQueue *q,ElemType e)
{
QueuePrt p;
p=(QueuePrt)malloc(sizeof(QNode));
if(!p)
exit(0);
p->data=e;
p->next=NULL;
q->rear->next=p;
q->rear=p;
}
void DeleteQueue(LinkQueue *q,ElemType *e)
{
QueuePrt p;
if(q->front==q->rear)
return;
p=q->front->next;
*e=p->data;
q->front->next=p->next;
if(q->rear==p)
q->rear=q->front;
free(p);
}
int main()
{
ElemType c;
LinkQueue q;
InitQueue(&q);
printf("请输入字符串\n");
scanf("%c",&c);
while(c != '#')
{
InsertQueue( &q, c);
scanf("%c",&c);
}
while(q.front != q.rear)
{
DeleteQueue(&q,&c);
printf("%c",c);
}
return 0;
} |
|