예제 #1
0
def testLinkedListRemovalOfLast():
    d = LinkedList()
    d.add("Hello")
    d.add("Bye")
    d.add("World")
    d.remove(2)
    return len(d)
예제 #2
0
def testLinkedListRemovalOfMiddle():
    c = LinkedList()
    c.add("Hello")
    c.add("Bye")
    c.add("Cya")
    c.add("World")
    c.remove(1)
    return len(c)
예제 #3
0
def testLinkedListAdd():
    l = LinkedList()
    l.add('Hello')
    l.add('Hello')
    l.add('Hello')
    l.add('Hello')
    return len(l)
예제 #4
0
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)
예제 #6
0
 def __init__(self):
     """
     This is the stack that is implemented using linked_list.
     """
     self.__container = LinkedList()
예제 #7
0
def testLinkedListRemovalOfHeadWithOthers():
    b = LinkedList()
    b.add("Hello")
    b.add("World")
    b.remove(0)
    return len(b)
예제 #8
0
def testLinkedListClearWithHead():
    a = LinkedList()
    a.add("hello")
    a.remove(0)
    return a.isEmpty()
예제 #9
0
def testLinkedListGet():
    l = LinkedList()
    l.add(10)
    l.add(1)
    return l.get(0)
예제 #10
0
def testLinkedListNotContains():
    l = LinkedList()
    l.add("hello")
    l.add("world")
    return l.contains("hellos")
예제 #11
0
def testLinkedListClear():
    e = LinkedList()
    e.add("Hello")
    e.add("World")
    e.clear()
    return e.isEmpty()