Beispiel #1
0
    def test_delete_first_item(sef):
        ll = Linked_list(array)
        item = 1

        if item == ll.head.data:
            ll.head = ll.head.next
        assert (ll.head.data == 2)
Beispiel #2
0
    def split(linked_list):
        if  linked_list == None or linked_list.head == None:
            left_half = linked_list
            right_half = None
            return left_half,right_half
        else:
            size = linked_list.size()
            mid = size // 2
            mid_node = linked_list.node_at_index(mid-1)
            left_half = linked_list
            right_half = Linked_list()
            right_half.head = mid_node.next_Node
            
            mid_node.next_Node = None    

        return left_half,right_half
Beispiel #3
0
    def merge(left,right):

        merge = Linked_list()
        merge.add(0)
        
        
        current = merge.head
        
    

        left_head = left.head
        
        right_head = right.head
      

        while left_head or right_head:
            

            if left_head is None:
                current.next_Node = right_head
                
                right_head = right_head.next_Node
                

            elif right_head is None:
                current.next_Node = left_head
                left_head = left_head.next_Node
            else:
                

                left_data = left_head.data    
                right_data = right_head.data 

                if left_data < right_data :
                    current.next_Node = left_head
                    left_head = left_head.next_Node
                else:
                    current.next_Node = right_head
                    right_head = right_head.next_Node
                   
            current = current.next_Node
            
        head = merge.head.next_Node    
        merge.head = head
        return merge