typedef struct node{ int data ; struct node *next ; }Node,*link ; 这个*link 代表什么意思阿?
3个回答
展开全部
*link 代表指向node这种类型结构体的指针。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
;stdio.h>
#include<stdlib.h>
typedef struct node
{int data;
struct node *next;
}listnode;
listnode *creat();
void output(listnode *L);
void insert(listnode *L,int i,int e);
int delet(listnode *L,int e);
main()
{int k,i,e;
listnode*L;
do
{
printf("\n");
printf("\n =====================") ;
printf("\n | 1.creat linklist |");
printf("\n | 2.delet |");
printf("\n | 3.insert |");
printf("\n | 4.end! |");
printf("\n =====================") ;
printf("\n\ninput the num(1,2,3,4): ");
scanf("%d",&k);
switch(k)
{
case 1:break;
case 2:{ printf("i=? ");scanf("%d",&i);e=delet(L,i);
if(e) printf("\n delet ok!\n");output(L);}break;
case 3:{ printf("i,e=? ");scanf("%d %d",&i,&e);
insert(L,i,e); output(L);} break;
}
}while(k!=4);
printf("\n Goodbye!!\n");
return 1;
}
listnode *creat() /*建立单链表*/
{
listnode *L,*r,*s;
int i,length,c;
L=(listnode *)malloc(sizeof(listnode));
L->next=NULL;
L->data=30000;
printf("input the length of the linklist: ");
scanf("%d",&length);
i=0;
while(i<length)
{
r=L;
printf("\ninput %dth num: ",i+1);
scanf("%d",&c);
while((r->next!=NULL)&&(r->data!=c))
r=r->next;
if(r->data!=c)
{
s=(listnode *)malloc(sizeof(listnode));
s->data=c;
s->next=NULL;
r->next=s;
i++;
}
}
return L;
}
void output(listnode *L) /*输出单链表数据*/
{
listnode *p;
printf("\n\nLinklist:") ;
p=L->next;
while(p!=NULL)
{
printf(" ->%3d",p->data);
p=p->next;
}
printf("\n\n") ;
}
void insert(listnode *L,int i,int e) /*在单链表中第i个结点前插入一个元素*/
{
listnode *pre,*s, *p;
int k=0, flag = 0;
pre=L;
p=L;
while(p!=NULL)
{
if (p->data == e)
{
flag = 1;
}
p=p->next;
}
if (flag == 0)
{
while(pre!=NULL && k<i-1)
{
pre=pre->next;
k++;
}
if(pre!=NULL)
{
s=(listnode *)malloc(sizeof(listnode));
s->data=e;
s->next=pre->next;
pre->next=s;
}
else printf("error!");
}
else
{
printf("insert error!");
}
}
int delet(listnode *L,int i) /*从单链表中删除第i个数据元素*/
{
listnode *pre,*r;
int k,e;
pre=L;
k=0;
while(pre->next!=NULL && k<i-1)
{pre=pre->next;
k=k+1;
}
if(pre->next!=NULL)
{r=pre->next;
pre->next=r->next;
e=r->data;
free(r);
return(1);
}
else
{printf("\ndelet error!\n");
return(0);
}
}
#include<stdlib.h>
typedef struct node
{int data;
struct node *next;
}listnode;
listnode *creat();
void output(listnode *L);
void insert(listnode *L,int i,int e);
int delet(listnode *L,int e);
main()
{int k,i,e;
listnode*L;
do
{
printf("\n");
printf("\n =====================") ;
printf("\n | 1.creat linklist |");
printf("\n | 2.delet |");
printf("\n | 3.insert |");
printf("\n | 4.end! |");
printf("\n =====================") ;
printf("\n\ninput the num(1,2,3,4): ");
scanf("%d",&k);
switch(k)
{
case 1:break;
case 2:{ printf("i=? ");scanf("%d",&i);e=delet(L,i);
if(e) printf("\n delet ok!\n");output(L);}break;
case 3:{ printf("i,e=? ");scanf("%d %d",&i,&e);
insert(L,i,e); output(L);} break;
}
}while(k!=4);
printf("\n Goodbye!!\n");
return 1;
}
listnode *creat() /*建立单链表*/
{
listnode *L,*r,*s;
int i,length,c;
L=(listnode *)malloc(sizeof(listnode));
L->next=NULL;
L->data=30000;
printf("input the length of the linklist: ");
scanf("%d",&length);
i=0;
while(i<length)
{
r=L;
printf("\ninput %dth num: ",i+1);
scanf("%d",&c);
while((r->next!=NULL)&&(r->data!=c))
r=r->next;
if(r->data!=c)
{
s=(listnode *)malloc(sizeof(listnode));
s->data=c;
s->next=NULL;
r->next=s;
i++;
}
}
return L;
}
void output(listnode *L) /*输出单链表数据*/
{
listnode *p;
printf("\n\nLinklist:") ;
p=L->next;
while(p!=NULL)
{
printf(" ->%3d",p->data);
p=p->next;
}
printf("\n\n") ;
}
void insert(listnode *L,int i,int e) /*在单链表中第i个结点前插入一个元素*/
{
listnode *pre,*s, *p;
int k=0, flag = 0;
pre=L;
p=L;
while(p!=NULL)
{
if (p->data == e)
{
flag = 1;
}
p=p->next;
}
if (flag == 0)
{
while(pre!=NULL && k<i-1)
{
pre=pre->next;
k++;
}
if(pre!=NULL)
{
s=(listnode *)malloc(sizeof(listnode));
s->data=e;
s->next=pre->next;
pre->next=s;
}
else printf("error!");
}
else
{
printf("insert error!");
}
}
int delet(listnode *L,int i) /*从单链表中删除第i个数据元素*/
{
listnode *pre,*r;
int k,e;
pre=L;
k=0;
while(pre->next!=NULL && k<i-1)
{pre=pre->next;
k=k+1;
}
if(pre->next!=NULL)
{r=pre->next;
pre->next=r->next;
e=r->data;
free(r);
return(1);
}
else
{printf("\ndelet error!\n");
return(0);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询