def helper_kthFromEnd(): ll = LinkList() ll.insert("2") ll.insert("8") ll.insert("3") ll.insert("1") return ll
def test_kthFromEnd_OneLinkList(): ll = LinkList() ll.insert("blah") #Where the linked list is of a size 1 actual = ll.kthFromEnd(0) expected = "blah" assert actual == expected
def test_append(): ll = LinkList() ll.insert('2') ll.insert('3') ll.insert('1') ll.append('5') expected = '1,3,2,5' actual = ll.toStr() assert expected == actual
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()
def test_insert(): ll = LinkList() ll.insert('one') assert ll.head.value == 'one'
def helper_insertBefore(): ll = LinkList() ll.insert('1') ll.insert('3') ll.insert('2') return ll