主题:[讨论]紧急求救!!!!!!大家来帮忙看看(循环队列方面的)
# include"stdio.h"
typedef struct node{
int data;
struct node *next;
}SNode;
typedef struct{
SNode *rear;
}QType;
void InitQueue(QType *qu){
qu->rear=(SNode *)malloc(sizeof(SNode));
qu->rear->next=qu->rear;
}
EnQueue(QType *qu,int x){
SNode *s;
s=(SNode *)malloc(sizeof(SNode));
s->data=x;
if (qu->rear==0){
qu->rear=s;
qu->rear->next=s;
}
else{
s->next=qu->rear->next;
qu->rear->next=s;
qu->rear=s;
}
printf("\n%d ",qu->rear->data);
}
int DeQueue(QType *qu){
SNode *p;
if (qu->rear==null)
return 0;
else{
p=qu->rear->next;
if (p==qu->rear)
qu->rear=null;
else{
qu->rear->next=p->next;
}
/* printf("@@@@@@@@@@@@@@@@@@@@"); */
printf("%d",p->data);
free(p);
}
}
/*void Print_Queue(QType *qu){
SNode *p;
p=qu->rear->next;
p=p->next;
while(p!=qu->rear){
printf("%d",p->data);
p=p->next;
}
printf("%d",p->data);
}*/
main(){
int i,n;int y;
QType La;
InitQueue(&La);
clrscr();
printf("input your nums:\n");
scanf("%d",&n);
printf("input your want nums:\n");
for(i=1;i<=n;++i){
scanf("%d",&y);
EnQueue(&La,y);
}
DeQueue(&La);
/* Print_Queue(&La);*/
}
为什么我打印不出出队后队里的值??????????我想只用尾指针做出来[em18][em18]
typedef struct node{
int data;
struct node *next;
}SNode;
typedef struct{
SNode *rear;
}QType;
void InitQueue(QType *qu){
qu->rear=(SNode *)malloc(sizeof(SNode));
qu->rear->next=qu->rear;
}
EnQueue(QType *qu,int x){
SNode *s;
s=(SNode *)malloc(sizeof(SNode));
s->data=x;
if (qu->rear==0){
qu->rear=s;
qu->rear->next=s;
}
else{
s->next=qu->rear->next;
qu->rear->next=s;
qu->rear=s;
}
printf("\n%d ",qu->rear->data);
}
int DeQueue(QType *qu){
SNode *p;
if (qu->rear==null)
return 0;
else{
p=qu->rear->next;
if (p==qu->rear)
qu->rear=null;
else{
qu->rear->next=p->next;
}
/* printf("@@@@@@@@@@@@@@@@@@@@"); */
printf("%d",p->data);
free(p);
}
}
/*void Print_Queue(QType *qu){
SNode *p;
p=qu->rear->next;
p=p->next;
while(p!=qu->rear){
printf("%d",p->data);
p=p->next;
}
printf("%d",p->data);
}*/
main(){
int i,n;int y;
QType La;
InitQueue(&La);
clrscr();
printf("input your nums:\n");
scanf("%d",&n);
printf("input your want nums:\n");
for(i=1;i<=n;++i){
scanf("%d",&y);
EnQueue(&La,y);
}
DeQueue(&La);
/* Print_Queue(&La);*/
}
为什么我打印不出出队后队里的值??????????我想只用尾指针做出来[em18][em18]