#include
#define M 10
typedef int QElemType;
typedef struct QNode
{
QElemType data;
QNode *next;
}*Queueptr;
void InitQueue(Queueptr &Q) //初始化队列
{
Q=new QNode;
Q->next=NULL;
}
int EnQueue(Queueptr Q,QElemType e) //元素如队列
{
Queueptr q=new QNode;
q->data=e;
q->next=NULL;
while(Q->next) Q=Q->next;
Q->next=q;
return 1;
}
void QueueSort(Queueptr Q) //队列排序
{
QElemType t;
Queueptr p,q,r;
r=Q;
while(r->next) //进行链表长度次循环
{
r=r->next;
p=Q->next; //初始化p指向队列第一个节点
while(p->next) //进行一轮比较
{
q=p->next;
if(p->data>q->data)
{
t=p->data;
p->data=q->data;
q->data=t;
}
p=q;
}
}
}
void QueueTreverse(Queueptr Q) //队列遍历
{
Queueptr p;
p=Q->next;
while(p)
{
printf("%d\t",p->data);
p=p->next;
}
printf("\n");
}
void main()
{
int i,j;
QElemType t;
Queueptr Q;
InitQueue(Q);
printf("请输入一组数据");
for(i=0;i
scanf("%d",&t);
EnQueue(Q,t);
}
QueueSort(Q);
printf("输出队列元素\n");
QueueTreverse(Q);
}