C 中的链接列表丢失部分
我正在尝试制作一个链接列表,但我在链接中间部分的概念上遇到了麻烦,我现在只是做了一些伪代码,实际上还没有编码任何内容。
(struct pointers) *current, *ahead, *behind, *begin;
(behind)-->(current)-->(ahead) //This is what I want to do
behind->next = current;
current->next = ahead;
这是断开和连接列表的正确方法吗?不失去任何东西..
I'm trying to make a link list and I'm having trouble with the concept with linking the middle part, I'm just doing a little pseudo-code right now, haven't actually coded anything.
(struct pointers) *current, *ahead, *behind, *begin;
(behind)-->(current)-->(ahead) //This is what I want to do
behind->next = current;
current->next = ahead;
Is this the proper way to break and connect the list? Without losing anything..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你所拥有的看起来是正确的,但并不完整。编程的一个不成文规则是,你不能第一次就正确地编写链表实现。有四种情况需要处理:
还有双向链表,其中每个元素都有一个指针到前一个元素和下一个元素。这使得处理诸如删除随机元素之类的事情变得更容易,而无需遍历列表,但要正确处理可能会更困难。
What you have looks correct but rather incomplete. One of the unwritten rules of programming is that you cannot write a linked list implementation correctly the first time. There are four cases you need to deal with:
There are also doubly-linked lists, where each element has a pointer to both the previous element and the next element. That makes it easier to handle things like removal of a random element without traversing the list, but can be trickier to get right.