帮忙看看哩!
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
typedef struct Node{
int data;
struct Node* next;
}sqlist;
void Createlistend(sqlist**L,int n){
sqlist*p,*q;
int i;
srand(time(NULL));
*L=(sqlist*)malloc(sizeof(sqlist));
q=*L;
for(i=0;i<n;i++){
p=(sqlist*)malloc(sizeof(sqlist));
p->data=rand()%100+1;
q->next=p;
q=p;
}
q->next=NULL;
}
int Getelem(sqlist* L,int i,int e){
int j;
sqlist* p;
p=L->next;
j=1;
while(p&&j<i){
p=p->next;
++j;
}
if(!p||j>i) exit(0);
e=p->data;
return e;
}
int main(){
sqlist* L,*p;
int n,i,k,e;
scanf("%d",&n);
Createlistend(&L,n);
p=L->next;
i=0;
while(p&&i<n){
printf("%d ",p->data);
p=p->next;
}
printf("\n");
scanf("%d",k);
e=Getelem(L,k,e);
printf("%d",e);
return 0;
}