//给定一批整数,以0作为结束标志且不作为结点,将
//其建成一个先进先出的链表,先进先出链表的指头指针
//始终指向最先创建的结点(链头),先建结点指向后建结
//点,后建结点始终是尾结点。
去感受,联想没接触指针时函数实参与形参
#include "stdio.h"
#include "stdlib.h"
struct s_list{
int data;
struct s_list *next;
} ;
void create_list (struct s_list **headp,int *p);
void main(void)
{
struct s_list *head=NULL,*p;
int s[]={1,2,3,4,5,6,7,8,0};
create_list(&head,s);
p=head;
while(p){
printf("%d\t",p->data);
p=p->next;
}
printf("\n");
return ;
}
void create_list(struct s_list **headp,int *p)
{
struct s_list * loc_head=NULL,*tail;
if(p[0]==0)
;
else {
loc_head=(struct s_list *)malloc(sizeof(struct s_list));
loc_head->data=*p++;
tail=loc_head;
while(*p){
tail->next=(struct s_list *)malloc(sizeof(struct s_list));
tail=tail->next;
tail->data=*p++;
}
tail->next=NULL;
}
*headp=loc_head;
return ;
}
#include "stdio.h"
#include "stdlib.h"
struct s_list{
int data;
struct s_list *next;
} ;
void create_list (struct s_list **headp,int *p);
void main(void)
{
struct s_list *head=NULL,*p;
int s[]={1,2,3,4,5,6,7,8,0};
create_list(&head,s);
p=head;
while(p){
printf("%d\t",p->data);
p=p->next;
}
printf("\n");
return ;
}
void create_list(struct s_list **headp,int *p)
{
struct s_list * loc_head=NULL,*tail;
if(p[0]==0) /* 相当于*p==0 */
;
else {
tail=(struct s_list *)malloc(sizeof(struct s_list));
tail->data=*p++;
tail->next=NULL;
while(*p){
loc_head=(struct s_list *)malloc(sizeof(struct s_list));
loc_head->data=*p++;
loc_head->next=tail;
tail=loc_head;
}
}
*headp=loc_head;
return ;
}