from linked_list import *

"""
https://leetcode.com/problems/delete-node-in-a-linked-list/

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.

Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, the linked list should become 1 -> 2 -> 4 after calling your function.
"""

def delete_node(node):
    node.data = node.next.data
    node.next = node.next.next


if __name__ == '__main__':
    a = Node(1)
    b = Node(2)
    c = Node(3)
    d = Node(4)

    a.next = b
    b.next = c
    c.next = d

    delete_node(c)

    res = a

    while res:
        print(str(res.data))
        print('\n')
        res = res.next
