chapter_array_and_linkedlist/linked_list/ #83
Replies: 98 comments 180 replies
-
请教k大,在fig.链表定义与存储方式图中,浅蓝色的存储结点指针是占用一块内存地址吗?还是和结点值各占一半呢?谢谢解答。 |
Beta Was this translation helpful? Give feedback.
-
请教k大!在看图Fig. 链表定义与存储方式和下面的代码时,感觉有些奇怪,这两个描述的是不是不是一个层面,在java中一切都是对象,那绿色的值的节点存的也是指针吧,那他们一个是内存层面一个是代码层面,不是一个层面的数据结构为什么能直接运用到java的对象中呢? |
Beta Was this translation helpful? Give feedback.
-
k神链表常用操作里,“输出结点在链表中的索引”,代码都是return -1, 是不是应该return index? |
Beta Was this translation helpful? Give feedback.
-
链表访问节点处的代码的for循环中,先令 head = head.next 再判断 head 是否为空,请问一下先判断head.next 是否为空,若为空则返回 null ;不为空再令 head = head.next 会不会好一点点。 |
Beta Was this translation helpful? Give feedback.
-
想问一下 链表的插入和删除确实是O(1) 但是查找既然是需要遍历。那应该是O(n)不是么? |
Beta Was this translation helpful? Give feedback.
-
刪除結點後,是不是把 P.next 設為 None比較好呢? |
Beta Was this translation helpful? Give feedback.
-
Fig. 在链表中插入与删除结点示意图中,插入操作示例 节点P的插入顺序错了,应该是 |
Beta Was this translation helpful? Give feedback.
-
想问一下github里,主函数里面为什么没有链表的定义,只有链表初始化?谢谢 |
Beta Was this translation helpful? Give feedback.
-
在链表插入操作中,请问一下可以写成这段代码吗:
|
Beta Was this translation helpful? Give feedback.
-
k神请教一个问题,python里的链表的定义比较好理解,定义了一个ListNode类,这个类有两个属性,一个是存储的值,另一个是指向下一个数据的地址。
但是c++的这个结构体的定义看着我有点迷糊。
|
Beta Was this translation helpful? Give feedback.
-
好清晰的说明,要是当时学数构有这边书就好了。(•̀ω•́ 」∠) |
Beta Was this translation helpful? Give feedback.
-
经典,膜拜的第n遍,每次阅读都有不一样的收获,对于我这种似懂非懂算法的小白来说。非常nice的开源项目~ |
Beta Was this translation helpful? Give feedback.
-
看这个之前自己也买了本书,最终发现还是作者讲得好啊。让我从原理明白了数据结构的魅力 |
Beta Was this translation helpful? Give feedback.
-
可以添加一些链表的常见应用 单向链表单向链表是一种常见的链表结构,每个节点包含一个指向下一个节点的指针。
环形链表首尾相接的链表结构,
双向链表双向链表是一种链表结构,每个节点都包含指向前一个节点和后一个节点的指针。
|
Beta Was this translation helpful? Give feedback.
-
大佬,请教一下,删除链表元素P的时候,N0指向N1就可以了,但是P还是指向的N1,那P最终是被GC回收了吗 |
Beta Was this translation helpful? Give feedback.
-
求教一下各位前辈,我想在vscode里自己尝试敲敲代码,但是在链表初始化那一步就有波浪线报错了。在构建结点之间的引用时(n0->next = n1;)系统报错“this declaration has no storage class or type specifier”,这是为什么呀T_T |
Beta Was this translation helpful? Give feedback.
-
请问佬们,我想模仿文中的后插入函数写前插入函数,但是不知道怎么表示传入节点前的节点,表示下一节点的引用时会用到想求的节点,VS提示使用了未初始化的内存,是只有两个方向都可以引用的列表才有前插操作吗? |
Beta Was this translation helpful? Give feedback.
-
请教一下各位大佬,就是当链表进行插入的时候,如果只知道要插入的位置的前节点的值,是不是复杂度就是O(n)了,因为需要从头开始遍历找到该值对应的节点。删除也是同理。 |
Beta Was this translation helpful? Give feedback.
-
JavaScript,留下足迹 |
Beta Was this translation helpful? Give feedback.
-
/* 在链表中查找值为 target 的首个节点 */
int Find(ListNode? head, int target) {
int index = 0;
while (head != null) {
if (head.val == target)
return index;
head = head.next;
index++;
}
return -1;
} 不是说返回节点吗?怎么变成返回值了?这里可能需要调整一下。 |
Beta Was this translation helpful? Give feedback.
-
/* 删除链表的节点 n0 之后的首个节点 */ |
Beta Was this translation helpful? Give feedback.
-
也可以编写一个循环将数组转换成链表,并封装成链表类的方法,方便链表的初始话,如Python: class ListNode:
def __init__(self, val: int):
self.val: int = val
self.next: ListNode | None = None
@staticmethod
def get_ls(nums: list) -> ListNode:
head = ListNode(nums[0]) if nums else None # 头节点
pre = head # 上一个节点
for i in range(1, len(nums)):
current = ListNode(nums[i])
pre.next = current # 上一个节点指向当前节点
pre = current # 更新上一个节点
return head
head = ListNode.get_ls([1, 2, 3, 4, 5]) |
Beta Was this translation helpful? Give feedback.
-
您好,如果加上 Linux Kernel 内 如何实现 链表内容,那内容将更加全面了. |
Beta Was this translation helpful? Give feedback.
-
您好,请问图是使用什么软件画出来的呢 |
Beta Was this translation helpful? Give feedback.
-
/* 访问链表中索引为 index 的节点 */ 有个地方我没弄懂,就是这段代码里head = head->next之后是否会导致越来越短,链表头结点会变成他的下一个节点吗 |
Beta Was this translation helpful? Give feedback.
-
def insert(n0: ListNode, P: ListNode): |
Beta Was this translation helpful? Give feedback.
-
有个疑问,我们在链表中实现插入/删除某个节点时,应该是头指针遍历到某个位置后,才能进行插入/删除。从这方面看,时间复杂度是O(n)。那我们平时在谈到链表的插入/删除操作时,时间复杂度应该是指哪一个?O(n)还是O(1)? |
Beta Was this translation helpful? Give feedback.
-
def insert(n0: ListNode, P: ListNode): |
Beta Was this translation helpful? Give feedback.
-
来信获悉,感谢您的支持!耑此奉复 钟冠彬This is an automatic reply, confirming that your e-mail was received.Thank you
|
Beta Was this translation helpful? Give feedback.
-
感谢来信,你的邮件已经收到。
|
Beta Was this translation helpful? Give feedback.
-
chapter_array_and_linkedlist/linked_list/
动画图解、一键运行的数据结构与算法教程
https://www.hello-algo.com/chapter_array_and_linkedlist/linked_list/
Beta Was this translation helpful? Give feedback.
All reactions