jia_xue 2016-10-30 03:48 采纳率: 0%
浏览 4969
已采纳

为什么不是struct node *而是struct node **大神帮忙

struct node
14
{
15
int data;
16
struct node* next;
17
};
18

19
/* 反转单链表. 分别用3个指针,指向前一个,当前,下一个 /
20
static void reverse(struct node
* head_ref)
21
{
22
struct node* prev = NULL;
23
struct node* current = head_ref;
24
struct node
next;
25
while (current != NULL)
26
{
27
next = current->next;
28
current->next = prev;
29
prev = current;
30
current = next;
31
}
32
head_ref = prev;
33
}
oid printList(struct node *head)
48
{
49
struct node *temp = head;
50
while(temp != NULL)
51
{
52
printf("%d ", temp->data);
53
temp = temp->next;
54
}
55
}
为什么不是struct node *而是struct node *
,第二个函数为什么又是,就这个很糊涂,大神帮忙

  • 写回答

4条回答 默认 最新

  • threenewbee 2016-10-30 03:52
    关注

    一般来说, 初始化链表之类的需要双指针(这里翻转链表因为不是在原始链表上翻转,而是返回新的链表头,所以也需要双指针)
    像求链表长度、插入节点、打印输出就只要单指针。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 已采纳回答 9月28日

悬赏问题

  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败