编程练习1
陈小q
这个作者很懒,什么都没留下…
展开
-
Python:链表的逆序
插入法:从链表的第二个节点开始,把遍历到的节点插入到头结点的后面,直到遍历结束class LNode: def __init__(self): self.data = None self.next = Nonedef Reverse(head): if head == None or head.next == None: ret...原创 2019-08-14 10:32:20 · 501 阅读 · 0 评论 -
Python:无序链表删除重复项
顺序删除,双重循环class LNode: def __init__(self): self.data = None self.next = Nonedef removeDou(head): if head == None or head.next == None : return outerCur = head.nex...原创 2019-08-14 11:12:23 · 236 阅读 · 0 评论 -
Python:如何计算两个单链表所代表的数之和
class LNode: def __init__(self): self.data = None self.next = Nonedef LAdd(h1,h2): if h1 == None or h1.next == None: return h2 if h2 == None or h2.next == None: ...原创 2019-08-14 16:10:57 · 227 阅读 · 0 评论 -
Python:如何找出单链表中的倒数第K个元素
class LNode: def __init__(self): self.data = None self.next = Nonedef ConstructList(): i = 1 head = LNode() cur = head while i<8 : tmp = LNode() ...原创 2019-08-14 16:36:20 · 462 阅读 · 0 评论 -
Python:如何检测一个较大的单链表是否有环
class LNode: def __init__(self): self.data = None self.next = Nonedef ConstructList(): i = 1 head = LNode() cur = head while i<8 : tmp = LNode() ...原创 2019-08-14 17:03:09 · 190 阅读 · 0 评论 -
Python:如何判断两个单链表(无环)是否交叉
Hash法首尾相接法:如把链表1 的尾结点接到链表2的头指针,然后判断链表2是否有环,参考如何判断一个单链表是否有环尾结点法class LNode: def __init__(self): self.data = None self.next = Nonedef IsIntersect(head1, head2): if head1 =...原创 2019-08-14 17:40:14 · 595 阅读 · 0 评论