|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
//按照编译提示的错误找了,但是还是不知道错误在哪哦,自学的新手菜鸟,请教各位大神
#include<stdio.h>
#include<stdlib.h>
#define N 41
typedef struct LNode
{
int data;
int num;
struct LNode * next;
}LNode, * pointer;
pointer create(int n)
{
pointer p = NULL, head, k;
int i=1;
head = (pointer)malloc(sizeof(LNode));
p = head;
if( n != 0 )
{
while(i <= n)
{
k = (pointer)malloc(sizeof(LNode));
k->data = i++;
k->num = rand()%100;
p->next = k;
p = k;
}
k->next = head->next;
free(head);
return (k->next);
}
int main()
{
int n = N, m, i;
pointer p = create(n), temp;
m = p->num;
while( p != p->next)
{
for(i=1; i<m; i++)
p = p->next;
printf("%d-->",p->next->data);
m = p->next->num;
temp = p->next;
p->next = temp->next;
free(temp);
p = p->next;
}
printf("%d",p->data);
return 0;
}
|
|