コード例 #1
0
ファイル: 2.2.py プロジェクト: ShwetaDixit/QureshiRepo
def main():
    head = Node(10)
    head.appendToTail(20, 's')
    head.appendToTail(46, 's')
    head.appendToTail(7654, 's')
    head.printLinkedList()
    print(kthElement(head, 3))
    head.printLinkedList()
コード例 #2
0
def main():
    head = Node(10)
    head.appendToTail(20, 's')
    head.appendToTail(46, 's')
    head.appendToTail(7654, 's')
    head.printLinkedList()
    midNode = head.findNode(10)
    delMiddleNode(midNode)
    head.printLinkedList()
コード例 #3
0
ファイル: 2.1.py プロジェクト: ShwetaDixit/QureshiRepo
def main():
    head = Node(10)
    head.appendToTail(20)
    head.appendToTail(50)  # Dupe
    head.appendToTail(30)
    head.appendToTail(120)
    head.appendToTail(50)  # Dupe
    head.appendToTail(10)
    head.appendToTail(15)
    head.printLinkedList()
    removeDupesDoubly(head)  # Should remove Dupes from LinkedList
    head.printLinkedList()
    return
コード例 #4
0
ファイル: 2.4.py プロジェクト: atherqureshi/QureshiRepo
    while(p):
        if p.val < pValue:
            before.append(p.val)
        elif p.val == pValue:
            p = p.next
            continue
        else:
            after.append(p.val)
        p = p.next
    # Make new list with before - pValue - after
    new_list = []
    new_list.extend(before)
    new_list.append(pValue)
    new_list.extend(after)
    p = head
    # iterate through linkedlist and change values
    for i in range(len(new_list)):
        p.val = new_list[i]
        p = p.next
    return


if __name__ in '__main__':
    head = Node(10)
    head.appendToTail(46, 's')
    head.appendToTail(20, 's')
    head.appendToTail(7654, 's')
    head.printLinkedList()
    partition_linked_list(head, 46)
    head.printLinkedList()
コード例 #5
0
ファイル: 2.4.py プロジェクト: aksinha01/QureshiRepo
    while (p):
        if p.val < pValue:
            before.append(p.val)
        elif p.val == pValue:
            p = p.next
            continue
        else:
            after.append(p.val)
        p = p.next
    # Make new list with before - pValue - after
    new_list = []
    new_list.extend(before)
    new_list.append(pValue)
    new_list.extend(after)
    p = head
    # iterate through linkedlist and change values
    for i in range(len(new_list)):
        p.val = new_list[i]
        p = p.next
    return


if __name__ in '__main__':
    head = Node(10)
    head.appendToTail(46, 's')
    head.appendToTail(20, 's')
    head.appendToTail(7654, 's')
    head.printLinkedList()
    partition_linked_list(head, 46)
    head.printLinkedList()
コード例 #6
0
            return pB
        if pA is pB:
            return pA
        visited.add(pA)
        visited.add(pB)
        if pA:
            pA = pA.next
        if pB:
            pB = pB.next
    return None


if __name__ in '__main__':
    # Making A LinkedLIst
    headA = Node(10)
    headA.next = Node(20)
    # Making B LinkedList
    headB = Node(765)
    headB.next = Node(543)
    headB.next.next = Node(432)
    # Creating Intersecting Node and appendingn to lists
    intersectNode = Node(40)
    headA.next.next = intersectNode
    headB.next.next.next = intersectNode
    # adding some more fluff nodes
    headA.next.next.next = Node(50)
    headA.next.next.next.next = Node(53)
    headA.printLinkedList()
    headB.printLinkedList()
    print(intersection(headA, headB).val)