return 值?
#include "stdio.h"
#include "stdlib.h"
#define OK 1
#define ERROR -1
#define NULL 0
#define OVERFLOW -2
typedef int ElemType;
typedef int Status;
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef struct node
{
int data;
struct node *next;
}Linklist;
Linklist * createlist(int n)
{
int k;
Linklist *head,*r,*p;
head=p=(Linklist *)malloc(sizeof(Linklist));
head->next=NULL;
for(k=1;k<=n;k++)
{
r=(Linklist *)malloc(sizeof(Linklist));
printf("input value:\n");
scanf("%d",&(r->data));
r->next=NULL;
p->next=r;
p=r;
}
return (head);
}
void Printlist(Linklist *head)
{
Linklist *p;
p=head->next;
while(p!=NULL)
{
printf("%4d",p->data);
p=p->next;
}
printf("\n");
}
Linklist * insert(Linklist *head,int i,int k)
{
Linklist *p;
Linklist *s;
int j=0;
p=head;
while(p&&j<i-1)
{
p=p->next;
j++;
}
if(!p||j>i-1)
{
return 0;
}
s=(Linklist *)malloc(sizeof(Linklist));
s->data=k;
s->next=p->next;
p->next=s;
return p; //这里是返回p的首地址吗?
}
Linklist *find(Linklist *head,int i)
{
int j;
Linklist *p;
p=head->next;
j=1;
while(p!=NULL&&j<i)
{
p=p->next;
j++;
}
printf("\n");
return p;
}
int main(int argc, char* argv[])
{
Linklist *L;
Linklist *q;
Linklist *head;
int x;
int k;
int select;
int i=0;
L=createlist(5);
Printlist(L);
printf("input i:\n");
scanf("%d",&i);
printf("input k:\n");
scanf("%d",&k);
insert(L,i,k);
Printlist(L);
printf("input i:\n");
scanf("%d",&i);
q=find(L,i);
printf("%d",q->data);
printf("\n");
return 0;
}