예제 #1
0
    def __init__(self, bins=32):
        self.bins = 32
        LinkedList.__init__(self)

        # HashTable is a linked list, where every item in the table is also
        # a linked list (i.e., a linked list of linked lists)
        for n in range(bins):
            self.insert(LinkedList())
예제 #2
0
 def __init__(self, size):
     if size > 0:
         LinkedList.__init__(self)
         self.size = size
         for num in xrange(size):
             self.insert(LinkedList())
     else:
         raise ValueError("size cannot be less than 1")
예제 #3
0
def profile_len(list_class: type, size: int) -> float:
    """Return the time taken to call len on a list of the given class and size.

    Precondition: list_class is either list or LinkedList.
    """
    # TODO: Create an instance of list_class containing <size> 0's.
    t = 0
    if isinstance(list_class, LinkedList):
        lsts = []
        for i in range(NUM_TRIALS):
            l = LinkedList()
            l.__init__(list(range(size)))
            lsts.append(l)
            for linklst in lsts:
                t += timeit('len(l)', number=1, globals=locals())
    # TODO: call timeit appropriately to check the runtime of len on the list.
    # Look at the Lab 4 starter code if you don't remember how to use timeit:
    # https://www.teach.cs.toronto.edu/~csc148h/fall/labs/w4_ADTs/starter-code/timequeue.py

    return t
예제 #4
0
class Stack():
    def __init__(self, iterable=()):
        self.other = LinkedList()
        self.other.__init__(iterable)

    def __repr__(self):
        return repr(self.other)

    def __str__(self):
        return str(self.other)

    def push(self, value):
        """Add a value to the head of the stack.

        args:
            value: The value to add to the stack
        """
        self.other.insert(value)

    def pop(self):
        """Remove a value from head of stack and return."""
        return self.other.pop()
예제 #5
0
class Stack():

    def __init__(self, iterable=()):
        self.other = LinkedList()
        self.other.__init__(iterable)

    def __repr__(self):
        return repr(self.other)

    def __str__(self):
        return str(self.other)

    def push(self, value):
        """Add a value to the head of the stack.

        args:
            value: The value to add to the stack
        """
        self.other.insert(value)

    def pop(self):
        """Remove a value from head of stack and return."""
        return self.other.pop()
예제 #6
0
파일: stack.py 프로젝트: sanjibm/PyDS
 def __init__(self):
     LinkedList.__init__(self)
 def __init__(self):
     self.head = None
     self.tail = None
     LinkedList.__init__(self)