【问题标题】:Why this C++ LinkedList statement is invalid?为什么这个 C++ LinkedList 语句无效?
【发布时间】:2021-01-04 15:48:52
【问题描述】:

我是 C++ 新手,目前正在研究它的数据结构。我在 Pointers 上看到了这个示例,但我无法说明它为什么无效。我在 Google 上搜索,但找不到答案。

问题:

Are the following expressions true or false
a.  head->next == ptr1     TRUE
b.  ptr1->next->data== 46      FALSE (Why!)
c.  ptr2->next == NULL     FALSE (Why!)
d.  head->data == 12       TRUE

【问题讨论】:

  • 你认为ptr1->next->data应该是什么?
  • 我相信它会打印出ptr1->next->data 会打印出34
  • 34等于46吗?
  • 你不能把你的手指放在这张照片上,然后按照每个问题的描述放开相应的箭头吗?
  • 我现在明白了,非常感谢你们,我现在觉得自己很愚蠢

标签: c++ pointers data-structures linked-list


【解决方案1】:

b. ptr1->next->data== 46 FALSE(为什么!)

ptr1 指向data24 的节点。该节点的next 指向data34 的节点。 data46 的节点after。因此,ptr1->next->next->data == 46 将改为 TRUE。

c。 ptr2->next == NULL FALSE(为什么!)

ptr2 指向data63 的节点。该节点的next 不是NULL,它指向data75 的节点。该节点的nextNULL。因此,ptr2->next->next == NULL 将改为 TRUE。

【讨论】:

    猜你喜欢
    • 2019-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-05
    • 2022-01-12
    • 2023-03-21
    • 2013-09-09
    • 1970-01-01
    相关资源
    最近更新 更多