主函数怎么调用函数(数据结构,创建链表)0
rnxm4460.09.29浏览179次分享举报
#include#include"stdlib.h"typedefintElemType;typedefstructnode{ElemTypedata;structnode*next;}slink;slink*creslink(intn){slink*head,*p,*s;inti;p=head=(slink*)mall... #include
#include "stdlib.h"
typedef int ElemType;
typedef struct node
{
ElemType data;
struct node *next;
}slink;
slink*creslink(int n)
{slink*head,*p,*s;
int i;
p=head=(slink *)malloc(sizeof(slink));
for(i=1;i<=n;i++)
{s=(slink *)malloc(sizeof(slink));
scanf("%d",&s->data);
p->next=s;
p=s;
}
p->next=NULL;
}
int getlen(slink *head)
{slink *p;
int n;
p=head->next;
n=0;
while(p!=NULL)
{n++;p=p->next;}
return n;
}
int delete(slink*head,int i,ElemType*e)
{slink*p,*q;
int j;
if(i<1)return 0;
p=head;
j=0;
while(p->next!=NULL&&j
{p=p->next;j++;}
if(p->next==NULL)return 0;
q=p->next;
p->next=q->next;
*e=q->data;
free(q);
return 1;
}
int insert(slink*head,int i,ElemType x)
{slink *p,*q;
int j;
if(i<1)return 0;
p=head;j=0;
while(p!=NULL)return 0;
q=(slink*)malloc(sizeof(slink));
q->data=x;
q->next=p->next;
p->next=q;
return 1;
}
void list(slink*head)
{slink*p;
p=head->next;
while(p!=NULL)
{printf("%4d",p->data);
p=p->next;
}
printf("\n");
}
void main(){
int n;
printf("please cread list\n");
} 展开