def __init__(self): SLL.__init__(self) # Meaningful aliases for enqueue and dequeue # for queue operations self.enqueue = self.push_back self.dequeue = self.pop_front
def test_sol(): l = SLL() l._create([1,2,3,4,5,6,7,8,9]) assert kth_elment_from_end(l.head, 1) == 9 assert kth_elment_from_end(l.head, 3) == 7 assert kth_elment_from_end(l.head, 9) == 1 assert kth_elment_from_end(l.head, 21) == -1
def __init__(self): SLL.__init__(self) # Meaningful aliases for push and pop # for stack operations self.push = self.push_front self.pop = self.pop_front
def __init__(self, comparatorfn=None): SLL.__init__(self) # Meaningful aliases for enqueue and dequeue # for queue operations self.dequeue = self.pop_front if comparatorfn: self.comparatorfn = comparatorfn else: # if no comparison is provided # try using standard cmp() self.comparatorfn = cmp
def test_sum(input, expected): li1 = SLL() li1._create(input[0]) li2 = SLL() li2._create(input[1]) assert pp(sum(li1.head, li2.head)) == expected assert pp(sum2(li1.head, li2.head)) == expected
def test_sol(): l = SLL() l._create([1, 2, 3, 4, 5]) delete_node(l.head.next.next) assert l.print_list() == [1, 2, 4, 5] delete_node(l.head.next.next.next) assert l.print_list() == [1, 2, 4, 5]
def concat(lst1, lst2): new = SLL() head = lst1.head while head != None: new.add(head.data) head = head.next head = lst2.head while head != None: new.add(head.data) head = head.next return new
from sll import SLL import random x = SLL() y = SLL() def concat(lst1, lst2): new = SLL() head = lst1.head while head != None: new.add(head.data) head = head.next head = lst2.head while head != None: new.add(head.data) head = head.next return new x.populate(5) y.populate(5) z = concat(x,y) z.iter()
def test_sol(): l = SLL() l._create([1]) l = solution(l.head) assert pprintl(l) == [1] l = SLL() l._create([1, 2, 1]) l = solution(l.head) assert pprintl(l) == [1, 2] l = SLL() l._create([1, 2, 1, 1, 2, 5, 5, 6, 1]) l = solution(l.head) assert pprintl(l) == [1, 2, 5, 6]
def test_sol(): l = SLL() node = solution(l.head, 2) assert pp(node) == [] l._create([6,5,7,4]) node = solution(l.head, 3) assert pp(node) == [6,5,7,4] assert pp(solution(l.head, 4)) == [6,5,7,4] l = SLL() l._create([6,5,7,4]) assert pp(solution(l.head, 5)) == [4,6,5,7] l = SLL() l._create([6,5,7,4]) assert pp(solution(l.head, 7)) == [6,5,4,7]
def test_sol(input, expected): l = SLL() l._create(input) assert is_palindrom(l.head) == expected
from sll import SLL from node import Node bob = SLL() def BuildMe(count): for i in range(count): bob.add_to_back(Node(i)) BuildMe(10) bob.print_me() bob.add_to_front(Node(42)) bob.print_me() print(bob.contains(100)) print(bob.contains(42))
def test_sol(range, cycle, expected): x = SLL() x._create(range) x = CLL(x, cycle) pr(x.head, 30) assert find_cycle_head(x.head) == expected