主题:谁能告诉我它的运行结果啊
告诉我运行结果吧
感谢不尽
#include<stdio.h>
#include<stdlib.h>
struct hv
{
int bhao;
int mma;
struct hv *next;
}*p,*q,*head;
main()
{
int m,n,b,i,j,c;
printf("please enter the number of people n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i==1)
{
head=p=(struct hv*)malloc(sizeof(struct hv));
if(p==0) return(0);
}
else
{
q=(struct hv*)malloc(sizeof(struct hv));
if(q==0) return(0);
p->next=q;
p=q;
}
printf("please enter the %d people's mima:",i);
scanf("%d",&(p->mma));
p->bhao=i;
}
p->next=head; /*使链表尾指向链表头 形成循环链表*/
p=head;
printf("please enter the number m:");
scanf("%d",&m);
for (j=1;j<=n;j++)
{
for(i=1;i<m;i++,p=p->next);
m=p->mma;
printf("%d",p->bhao);
p->bhao=p->next->bhao;
p->mma=p->next->mma;
q=p->next;
p->next=p->next->next;
free(q);
}
}
感谢不尽
#include<stdio.h>
#include<stdlib.h>
struct hv
{
int bhao;
int mma;
struct hv *next;
}*p,*q,*head;
main()
{
int m,n,b,i,j,c;
printf("please enter the number of people n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i==1)
{
head=p=(struct hv*)malloc(sizeof(struct hv));
if(p==0) return(0);
}
else
{
q=(struct hv*)malloc(sizeof(struct hv));
if(q==0) return(0);
p->next=q;
p=q;
}
printf("please enter the %d people's mima:",i);
scanf("%d",&(p->mma));
p->bhao=i;
}
p->next=head; /*使链表尾指向链表头 形成循环链表*/
p=head;
printf("please enter the number m:");
scanf("%d",&m);
for (j=1;j<=n;j++)
{
for(i=1;i<m;i++,p=p->next);
m=p->mma;
printf("%d",p->bhao);
p->bhao=p->next->bhao;
p->mma=p->next->mma;
q=p->next;
p->next=p->next->next;
free(q);
}
}