先进先出,先进后出单链表&&c语言指向指向结构体的指针的指针

//给定一批整数,以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 ;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值