Example #1
0
def list_to_positional_list(L):
    pos_list = PositionalList()

    for i in L:
        pos_list.add_last(i)

    return pos_list
def list_to_positional_list(list_):

    new_pos_list = PositionalList()

    for element in list_:
        new_pos_list.add_last(element)
    return new_pos_list
Example #3
0
 def top(self, k):
     if not 1 <= k <= len(self):
         raise ValueError('Illegal value for k')
     temp = PositionalList()
     for item in self._data:
         temp.add_last(item)
     for j in range(k):
         highPos = temp.first()
         walk = temp.after(highPos)
         while walk is not None:
             if walk.element()._count > highPos.element()._count:
                 highPos = walk
         yield highPos.element()._value
         temp.delete(highPos)
Example #4
0
 def __init__(self):
     self.__verts = list()
     self.__faces = PositionalList()
     self.__polygon_types = list(
     )  # RP: shape of polygon or the name of n-gon
     self.__numberOfVertices = 0  # RP: total number of vertices
     self.__totalPolygons = 0  # RP: total number of faces
     self.__polygons = dict(
     )  # RP: count of each type of faces, 3 squares, 5 pentagons etc
     self.__x_minimum = 0  # RP: minimum of x co-ordinates
     self.__y_minimum = 0  # RP: minimum of y co-ordinates
     self.__z_minimum = 0  # RP: minimum of z co-ordinates
     self.__x_maximum = 0  # RP: maximim of x co-ordinates
     self.__y_maximum = 0  # RP: maximim of y co-ordinates
     self.__z_maximum = 0  # RP: maximim of z co-ordinates
Example #5
0
def main():
    global screen, polygonList, mainloop

    polygonList = PositionalList()

    mainloop = True

    while mainloop:

        pygame.time.Clock().tick(FPS)
        screen.blit(background, (0, 0))

        update()
        draw()

        pygame.display.update()

    pygame.quit()
 def top(self, k):
     """Generate sequence of top k elements in terms of access count."""
     if not 1 <= k <= len(self):
         raise ValueError('Illegal value for k')
     # we begin by making a copy of the original list
     temp = PositionalList()
     for item in self._data:  # positional lists support iteration
         temp.add_last(item)
     # we repeatedly find, report, and remove element with largest count
     for j in range(k):
         # find and report next highest from temp
         highPos = temp.first()
         walk = temp.after(highPos)
         while walk is not None:
             if walk.element()._count > highPos.element()._count:
                 highPos = walk
             walk = temp.after(walk)
         # we have found the element with highest count
         yield highPos.element()._value  # report element to user
         temp.delete(highPos)  # remove from temp list
Example #7
0
    def top(self, k):
        if k < 1 or k > len(self._data):
            raise ValueError("Invalid value for k.")

        tmp = PositionalList()
        for i in range(len(self._data)):
            tmp.add_first(self._data.delete(self._data.first()))

        for i in range(k):
            p = tmp.first()
            p_max = tmp.first()
            max = p.element()._value

            while p != None:
                if p.element()._value > max:
                    p = self._data.after(p)
                    p_max = p.element()
                    max = p_max._value

            yield max
    def top(self, k):
        """Generate sequence of top k elements in terms of access count."""
        if not 0 <= k <= len(self):
            raise ValueError("Illegal value for k")

        # we begin my making copy of original list, as we will modify the temprary list
        temp = PositionalList()
        for item in self._data:  # positional list supports iteration
            temp.add_last(item)

        # we repeatedly find, report, and remove elements with largest count from temp list
        for j in range(k):
            # find and report next highest from temp
            highPos = temp.first()
            walk = temp.after(highPos)
            while walk != None:
                if walk.element()._count > highPos.element()._count:
                    highPos = walk
                walk = temp.after(walk)
            # we have found element with the highest count
            yield highPos.element()._value  # report element to user
            temp.delete(
                highPos)  # remove from temp to get next most accessed element
Example #9
0
 def __init__(self):
   """Create a new empty Priority Queue."""
   self._data = PositionalList()
 def __init__(self):
     """Create an empty list of favorites."""
     self._data = PositionalList()  # will be list of _Item instances
Example #11
0
 def __init__(self):
     #empty priority queue
     self._data = PositionalList()
Example #12
0
 def clear(self):
     self._data = PositionalList()
Example #13
0
 def __init__(self):
     """Create an empty list of favorites."""
     self._data = PositionalList(
     )  # Will be a list of _Item instances (from nested class above)
 def __init__(self):
     self._data = PositionalList()
Example #15
0
# -*- coding: utf-8 -*-
from positional_list import PositionalList

def max(pl):
    """ Return the max element of the positional list pl. Return None if the
    list is empty."""
    if pl.is_empty():
        return None
    rlt = pl.first().element()
    for item in pl:
        if item > rlt:
            rlt = item.element()
    return rlt

if __name__ == '__main__':
    pl = PositionalList()
    for i in range(10000):
        pl.add_first(i)
    print('max: {0:d}'.format(max(pl)))

    """Print all elements of PositionalList as a string."""
    print(", ".join([str(elem) for elem in L]))


def clear_positional_list(L):
    """Delete all elements from PositionalList."""
    pos1 = L.first()
    while len(L) > 0:
        pos2 = L.after(pos1)
        L.delete(pos1)
        pos1 = pos2


if __name__ == "__main__":
    # Test 1: print_positional_list(), clear_positional_list()
    PL = PositionalList()
    for i in range(0, 38, 2):
        PL.add_last(i)
    print("before deletion:")
    print_positional_list(PL)
    print("length =", len(PL))
    clear_positional_list(PL)
    print("after deletion:")
    print_positional_list(PL)
    print("length =", len(PL))

    # Test 2: print_positional_list(), clear_positional_list()
    print()
    PL.add_last("apple")
    PL.add_last("orange")
    PL.add_last("pear")
Example #17
0
from positional_list import PositionalList

posList = PositionalList()

posList.add_last("hello")
posList.add_last("test")
posList.add_last("middle")
posList.add_last("goodbye")
posList.add_last("end")
posList.add_last("hello")