修改指针内容 修改指针地址 问题

本文深入探讨了使用C语言实现链表的基本操作,包括链表的创建、插入、删除以及遍历。详细解释了链表的数据结构定义、函数实现,并通过实例展示了如何灵活运用链表进行数据存储与管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

#include<stdio.h>
#include<malloc.h>
#define LEN sizeof(linkstack)
typedef struct node
{
    int data;
    struct node *next;
}linkstack;
linkstack *push(linkstack *top,int x);
void print(linkstack *top);
void main()
{
    linkstack *top=(struct node*)malloc(LEN);
    top->next=NULL;
    top->data=-99;
    int x;             
   printf("请输入数据:");
  scanf("%d",&x);
  top=push(top, x);
//push函数中的传入的top指针,修改其内容是完全OK的;但是修改top指针的地址top=p会没有效果,为了解决这个问题,要用返回值解决问题!!
linkstack
*push(linkstack *top,int x) { linkstack *p; p=(struct node *)malloc(LEN); p->data=x; p->next=top; top=p; return(top); }void print(linkstack *top) { linkstack *t; t=top; while(t->next!=NULL) { printf("%d\t",t->data); t=t->next; } }

 

转载于:https://www.cnblogs.com/yexuannan/p/3254714.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值