猴子大王,然我哭了无数遍
现在改成这样,刚才的我已经完全没办法,不会搞了。。但是最后的结果很不对#include<stdio.h>
#include<malloc.h>
#define MONKEY_NUMBER 50
typedef int datatype;
typedef struct node
{
datatype number;
struct node *next;
}Linklist;
Linklist *head,*s,*t,*r;
Linklist *p;
int main()
{
void Sign_number(Linklist *,Linklist*,Linklist*);
void Circulate_main(Linklist *,Linklist*,Linklist*);
t = (Linklist*)malloc(sizeof(Linklist));
head = t;
s = (Linklist*)malloc(sizeof(Linklist));
Sign_number(head,s,t);
Circulate_main(head,s,t);
return 0;
}
void Sign_number(Linklist *head,Linklist *s,Linklist *t)
{
int i,j,k;
for(i = 0;i < MONKEY_NUMBER;i++)
{
s = (Linklist*)malloc(sizeof(Linklist));
s->number = i + 1;
t->next = s;
t = s;
}
s->next = head->next;
s = head->next;
for(j = 0;j < 50;j++)
{
printf("%2d ",s->number);
s = s->next;
}
}
void Circulate_main(Linklist *head,Linklist *s,Linklist *t)
{
int i,j,k;
s = head->next;
while(s->next != s)
{
for(i = 0;i < 3;i++)
{
t = s;
s = s->next;
}
t->next = s->next;
printf("%2d",s->number);
free(s);
s = t->next;
}
printf("%2d",s->number);
getchar();
getchar();
}