#!/usr/bin/env python
# -*- coding: UTF-8 -*-
__author__ = 'Julio Tentor <[email protected]>'
import numpy
class Queue(object):
def __init__(self, capacity = 10):
self.__capacity = capacity
self.__data = numpy.empty(self.__capacity, numpy.object)
self.__head = 0
self.__tail = 0
self.__count = 0
def __len__(self):
return self.__count
def __next__(self, pos):
pos += 1
return 0 if (pos >= self.__capacity) else pos
def append(self, x):
if self.__count >= self.__capacity:
raise ValueError("ERROR La cola está llena...")
self.__data[self.__tail] = x
self.__tail = self.__next__(self.__tail)
self.__count += 1
def popleft(self):
if self.__count <= 0:
raise ValueError("ERROR La cola está vacía...")
result = self.__data[self.__head]
self.__head = self.__next__(self.__head)
self.__count -= 1
return result
if __name__ == "__main__":
pass
Comments