Exemple #1
0
 def __init__(self):
     """
     (StackAsLinkedList)
     Constructs a stack.
     """
     super(StackAsLinkedList, self).__init__()
     self._list = LinkedList()
Exemple #2
0
 def purge(self):
     """
     (BinomialQueue) -> None
     Purges this binomial queue.
     """
     self._treeList = LinkedList()
     self._count = 0
Exemple #3
0
 def merge(self, queue):
     """
     (BinomialQueue, BinomialQueue) -> None
     Merges the contents of the given binomial queue
     with this binomial queue.
     """
     oldList = self._treeList
     self._treeList = LinkedList()
     self._count = 0
     p = oldList.head
     q = queue._treeList.head
     carry = None
     i = 0
     while p is not None or q is not None \
             or carry is not None:
         a = None
         if p is not None:
             tree = p.datum
             if tree.degree == i:
                 a = tree
                 p = p.__next__
         b = None
         if q is not None:
             tree = q.datum
             if tree.degree == i:
                 b = tree
                 q = q.__next__
         (sum, carry) = BinomialQueue.fullAdder(a, b, carry)
         if sum is not None:
             self.addTree(sum)
         i += 1
     queue.purge()
Exemple #4
0
 def purge(self):
     """
     (OrderedListAsLinkedList) -> None
     Purges this ordered list.
     """
     self._linkedList = LinkedList()
     self._count = 0
 def __init__(self):
     """
     (QueueAsLinkedList) -> None
     Constructs a queue.
     """
     super(QueueAsLinkedList, self).__init__()
     self._list = LinkedList()
Exemple #6
0
 def __init__(self):
     """
     (OrderedListAsLinkedList) -> None
     Constructs an ordered list.
     """
     super(OrderedListAsLinkedList, self).__init__()
     self._linkedList = LinkedList()
Exemple #7
0
 def __init__(self, n):
     """
     (MultisetAsLinkedList, int) -> None
     Constructs a multiset with the given universe size.
     """
     super(MultisetAsLinkedList, self).__init__(n)
     self._list = LinkedList()
Exemple #8
0
 def __init__(self, size):
     """
     (GraphAsLists, int) -> None
     Constructs a graph with the given maximum number of vertices.
     """
     super(GraphAsLists, self).__init__(size)
     self._adjacencyList = Array(size)
     for i in range(size):
         self._adjacencyList[i] = LinkedList()
Exemple #9
0
 def __init__(self, key):
     """
     (GeneralTree, Object) -> None
     Constructs a general tree with the given object at its root.
     """
     super(GeneralTree, self).__init__()
     self._key = key
     self._degree = 0
     self._list = LinkedList()
 def __init__(self, length):
     """
     (ChainedHashTable, int) -> None
     Constructs a chained hash table with the given length.
     """
     super(ChainedHashTable, self).__init__()
     self._array = Array(length)
     for i in xrange(len(self._array)):
         self._array[i] = LinkedList()
 def __init__(self, numberOfRows, numberOfColumns):
     """
     (SparseMatrixAsLinkedList, int, int) -> None
     Constructs a sparse matrix with the given number of rows and columns.
     """
     super(SparseMatrixAsLinkedList, self).__init__(numberOfRows,
                                                    numberOfColumns)
     self._lists = Array(numberOfRows)
     for i in xrange(numberOfRows):
         self._lists[i] = LinkedList()
Exemple #12
0
 def __init__(self, *args):
     """
     (BinomialQueue, ...) -> None
     Constructor.
     """
     super(BinomialQueue, self).__init__()
     self._treeList = LinkedList()
     if len(args) == 0:
         pass
     elif len(args) == 1:
         assert isinstance(args[0], self.BinomialTree)
         self._treeList.append(args[0])
     else:
         raise ValueError
Exemple #13
0
 def purge(self):
     """
     (MultisetAsLinkedList) -> None
     Purges this multiset.
     """
     self._list = LinkedList()
Exemple #14
0
 def __init__(self):
   self._list = LinkedList()