Beispiel #1
0
def test_insert_tail():
    l = SingleLinkedList()
    for i in range(5):
        l.push_back(i)

    l.insert(4, 33)

    assert l.tail.data == 33
    assert l.length == 6
Beispiel #2
0
def test_insert_middle():
    l = SingleLinkedList()

    for i in range(10):
        l.push_back(i)

    l.insert(3, 99)

    assert l.head.next.next.next.data == 99
    assert l.head.next.next.next.next.data == 3
Beispiel #3
0
def test_instert_head():
    l = SingleLinkedList()
    for i in range(5):
        l.push_back(i)

    assert l.head.data == 0
    assert l.tail.data == 4

    l.insert(0, 33)
    assert l.head.data == 33
class Stack:
    def __init__(self):
        self._sll = SingleLinkedList()

    def push(self, value):
        node = Node(value)
        self._sll.insert(node, pos=0)

    def pop(self):
        if self._sll.isEmpty():
            raise Exception("Empty Stack")

        node = self._sll.head
        self._sll.head = self._sll.head.next
        return node.value