def test_remove():
    ll = LinkList()
    helper_insert_many(ll)
    actual = ll.remove('5')
    expected = True
    assert actual == expected
    assert ll.count() == 9
def test_insert_many():
    ll = LinkList()
    helper_insert_many(ll)
    assert ll.count() == 10
    assert ll.head.value == '9'
    assert ll.head.next.value == '8'
    assert ll.head.next.next.value == '7'
    assert ll.head.next.next.next.value == '6'
    assert ll.head.next.next.next.next.value == '5'
    assert ll.head.next.next.next.next.next.value == '4'
    assert ll.head.next.next.next.next.next.next.value == '3'
    assert ll.head.next.next.next.next.next.next.next.value == '2'
    assert ll.head.next.next.next.next.next.next.next.next.value == '1'
    assert ll.head.next.next.next.next.next.next.next.next.next.value == '0'
    assert ll.head.next.next.next.next.next.next.next.next.next.next is None
Exemplo n.º 3
0
class Stack():

    _data = None

    def __init__(self):
        self._data = LinkList()

    def count(self) -> int:
        return self._data.count()

    def pop(self) -> object:
        b, val = self._data.peekHead()
        if b:
            self._data.remove(val)
        return val

    def push(self, val: object) -> bool:
        self._data.insert(val)
        return True

    def peek(self) -> [bool, object]:
        return self._data.peekHead()
Exemplo n.º 4
0
class Queue():
    def __init__(self):
        self._data = LinkList()

    def count(self) -> int:
        return self._data.count()

    def toStr(self) -> str:
        return self._data.toStr()

    def enqueue(self, val) -> bool:
        # Add a value to the queue
        return self._data.append(val)

    def dequeue(self, val) -> bool:
        # Remove entry from queue with a given value
        # NOTE: will only remove the first element found with val
        return self._data.remove(val)

    def peek(self) -> [bool, object]:
        # Get value from the head of the queue (without removing it)
        return self._data.peekHead()
def test_count():
    ll = LinkList()
    helper_insert_many(ll)
    expected = 10
    actual = ll.count()
    assert actual == expected