c - 两个链表的交集

标签 c algorithm data-structures

给定两个排序链表 L1 和 L2,计算它们的解决方案 路口 L1 路口 L2

最佳答案

L1_node = L1.head;
L2_node = L2.head;
Result = new SList;
while L1_node != NULL and L2_node != NULL:
  if L1_node.value == L2_node.value:
     Result.append(L1_node.value)
     L1_node = L1_node.next
     L2_node = L2_node.next
  elif L1_node.value < L2_node.value:
     L1_node = L1_node.next
  else
     L2_node = L2_node.next

(自己翻译成C。)

关于c - 两个链表的交集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2171446/

相关文章:

c - 为什么这个宏没有正确扩展?

C画面旋转优化

c - C 中列表的第一个元素不正确(linux/list.h)

algorithm - 高度为 h 的节点数是多少?

arrays - 如果我们将数组划分为 log(n) 而不是 2,时间复杂度是多少?

algorithm - 双循环与操作次数的关系

c - C 中的 Heapify 问题

python - 第二次添加到列表后,我的 Python 链表实现崩溃

C - 将半字节从一个字节复制到另一个字节以生成 4 位位移

algorithm - 如何从文件中删除重复项?