#include <stdio.h>
#include <malloc.h>
#define N 100; //该循环队列最多可容纳100个元素
#define L sizeof(struct Q)
int m=5,t; //最先在空的队列里压入5个元素
struct Q
{
int num; //指针及变量的定义
struct Q *next;
};
struct Q *create(void)
{struct Q *head,*p,*last;
int i;
last=(struct Q*)malloc(L); //开辟指针域
printf("input %d records\n",m); //打印输入的元素个数
scanf("%d",&last->num);
head=last;
for(i=2;i<=m;i++) //队列的初始话,压入元素
{ p=(struct Q*)malloc(L);
scanf("%d",&p->num);
last->next=p;
last=last->next;
}
last->next=head;
return last;
}
void printlist(struct Q *head) //对队列进行打印操作
{struct Q *p;
printf("The queue list is :\n");
p=head;
printf("%d\n",p->num);
p=p->next;
while(p!=head)
{
printf("%d\n",p->num);
p=p->next;
}
printf("the stack's length is %d\n",m);
}
struct Q *del(struct Q *last) //对队列进行删除操作
{
struct Q *p,*head; //头节点后移
head=last->next;
last->next=head->next;
m--;
free(head);
return last; //返回尾节点
}
struct Q *ins(last,insert) //队列的插入操作
struct Q *last,*insert;
{
struct Q *head=last->next;
last->next=insert;
last=last->next;
insert->next=head;
m++; //队列中元素个数的计数
return last; //返回尾节点
}
main() //主函数
{struct Q //定义各变量,及指针
*last,*newne;
last=create(); //进行相关的操作
printlist(last->next);
newne=(struct Q *)malloc(L);
printf("please input number you want to insert:\n");
scanf("%d",&t);
newne->num=t;
last=ins(last,newne);
printlist(last->next);
last=
printlist(last->next);
printf("\ngood bye!\n");
}