def testLinkedListRemovalOfLast(): d = LinkedList() d.add("Hello") d.add("Bye") d.add("World") d.remove(2) return len(d)
def testLinkedListRemovalOfMiddle(): c = LinkedList() c.add("Hello") c.add("Bye") c.add("Cya") c.add("World") c.remove(1) return len(c)
def testLinkedListAdd(): l = LinkedList() l.add('Hello') l.add('Hello') l.add('Hello') l.add('Hello') return len(l)
class Stack: top = -1 def __init__(self): """ This is the stack that is implemented using linked_list. """ self.__container = LinkedList() def __repr__(self): return '{} len={} peek={}'.format(self.__class__.__name__, self.top, self.peek()) def pop(self): """ :return: """ if self.top < 0: raise IndexError('stack index out or range') head = self.__container.head.data if self.__container.head is not None else None del self.__container[0] self.top -= 1 return head def peek(self): return self.__container.head.data if self.__container.head is not None else None def push(self, other): """ :return: """ self.__container.prepend(other) self.top += 1 def isEmpty(self): if self.top < 0: return True return False
from structs import LinkedList ll = LinkedList() ll += 'Danny' ll += 2 ll += 3 ll += 4 ll += 5 ll[4] = 'Johnny' ll.insert(4, 'Homey') ll.add('Homey') ll.insert(6, 'Holy') del ll[7] print(len(ll)) # for i in ll: # print(i) print(len(ll)) print('Danny' in ll)
def __init__(self): """ This is the stack that is implemented using linked_list. """ self.__container = LinkedList()
def testLinkedListRemovalOfHeadWithOthers(): b = LinkedList() b.add("Hello") b.add("World") b.remove(0) return len(b)
def testLinkedListClearWithHead(): a = LinkedList() a.add("hello") a.remove(0) return a.isEmpty()
def testLinkedListGet(): l = LinkedList() l.add(10) l.add(1) return l.get(0)
def testLinkedListNotContains(): l = LinkedList() l.add("hello") l.add("world") return l.contains("hellos")
def testLinkedListClear(): e = LinkedList() e.add("Hello") e.add("World") e.clear() return e.isEmpty()