示例#1
0
    def _get_sample_linkedlist(self, size=4):
        """Create a sample linkedlist and return the linkedlist obj."""
        ll = LinkedList()

        for item in range(size):
            ll.push(item)

        return ll
def test_insert_sorted_five():
    ll = LinkedList()
    ll.push(1)
    ll.push(2)
    ll.push(3)
    ll.push(4)

    head = insertsorted(ll.head, 10)

    assert(_get_all_data(head)==[1,2,3,4,10])
示例#3
0
def test_deleteduplicates_two():
    ll = LinkedList()
    ll.push(1)
    ll.push(2)
    ll.push(3)

    head = deleteduplicates(ll.head)
    result = _get_all_data(head)

    assert (result == [1, 2, 3])
示例#4
0
def test_deleteduplicates_one():
    ll = LinkedList()
    ll.push(1)
    ll.push(1)
    ll.push(1)

    head = deleteduplicates(ll.head)
    result = _get_all_data(head)

    assert (result == [1])
示例#5
0
def test_reorg_two():
    ll = LinkedList()
    ll.push(0)
    ll.push(1)
    ll.push(2)
    ll.push(3)

    print " "

    result = _get_all_data(ll.head)
    print result

    head = reorg(ll.head)
    result = _get_all_data(head)
    print result
    
    assert(result == [0,2,1,3])
def test_mergetwolists_one():
    ll1 = LinkedList()
    ll1.push(-10)
    ll1.push(-10)
    ll1.push(-9)
    ll1.push(-4)
    ll1.push(1)
    ll1.push(6)
    ll1.push(6)

    ll2 = LinkedList()
    ll2.push(-7)

    solution = Solution()
    head = solution.mergeTwoLists(ll1.head, ll2.head)

    result = _get_all_data(head)
    assert(result==[-10,-10,-9,-7,-4,1,6,6])
示例#7
0
def test_merge_node_noextraspace():
    ll = LinkedList()
    ll.push(3)
    ll.push(1)
    ll.push(2)

    ll_one = LinkedList()
    ll_one.push(10)
    ll_one.push(20)

    ll_two = LinkedList()
    ll_two.push(5)

    ll_one.get(1).next = ll.head
    ll_two.get(0).next = ll.head
示例#8
0
def test_merge_node():
    ll = LinkedList()
    ll.push(3)
    ll.push(1)
    ll.push(2)

    ll_one = LinkedList()
    ll_one.push(10)
    ll_one.push(20)

    ll_two = LinkedList()
    ll_two.push(5)

    ll_one.get(1).next = ll.head
    ll_two.get(0).next = ll.head

    assert (mergenode_extraspace(ll_one.head, ll_two.head).data == 3)
def test_insert_sorted_three():
    ll = LinkedList()
    ll.push(3)
    ll.push(4)
    ll.push(5)
    ll.push(10)

    head = insertsorted(ll.head, 1)

    assert(_get_all_data(head)==[1,3,4,5,10])
def test_insert_sorted_two():
    ll = LinkedList()
    ll.push(1)
    ll.push(2)
    ll.push(5)
    ll.push(10)

    head = insertsorted(ll.head, 3)

    assert(_get_all_data(head)==[1,2,3,5,10])
def test_partition_x():
    ll = LinkedList()
    ll.push(1)
    ll.push(4)
    ll.push(3)
    ll.push(2)
    ll.push(5)
    ll.push(2)

    head = partition_x(ll.head, 3)
    cur = head
    while cur is not None:
        print cur.data
        cur = cur.next


            
示例#12
0
def test_splitoddeven_two():
    ll = LinkedList()
    ll.push(2)
    ll.push(3)
    ll.push(4)
    ll.push(2)
    ll.push(9)

    print(_get_all_data(ll.head))

    odd, even = splitoddeven(ll.head)

    print(_get_all_data(odd))
    print(_get_all_data(even))

    assert (isoddlist(odd) == True)
    assert (isevenlist(even) == True)
示例#13
0
def test_reorg_one():
    ll = LinkedList()
    ll.push(0)
    ll.push(1)
    ll.push(2)
    ll.push(3)
    ll.push(4)
    ll.push(5)
    ll.push(6)
    ll.push(7)
    ll.push(8)
    ll.push(9)
    ll.push(10)
    ll.push(11)

    print " "

    result = _get_all_data(ll.head)
    print result

    head = reorg(ll.head)
    result = _get_all_data(head)
    print result
    
    assert(result == [0,2,1,5,4,3,9,8,7,6,11,10])