mardi 28 juin 2016

Radix sorting, "Queue" object not iterable


I've come to an end with my assignment, I don't know where I go from where I am right now, the code is currently looking like this:

def radixsorting1(n,m):
    div=1
    mod=10
    bin_list=[]
    alist=[]
    r=[]
    for bins in range(0,10):
        bin_list.append(Queue())
    for k in range(0,m):
        r.append(random.randint(1,10**n))
    if not len(r)==0:
        o=max(r)
        y=len(str(o))
    for p in range(y):
        for num in alist:
            minsta_tal=value%mod
            minsta_tal=int(minsta_tal//div)
            bin_list[minsta_tal].put(num)
        s=[]
        for bins in bin_list:
            while not bins.isempty():
                s.append(bins.dequeue())
    return s  

What I've been trying to do is to create 10 queues in put them in a list, then random m numbers from 1 to 10^n. Lets say I get 66 and 72, then I first sort them by the "small number", that is 6 and 2 in my numbers, then put them in a lost, and then do the process all over again but for the number 6 and 7 (the bigger number). In its current shape I get the error "Queue" object is not iterable.

My Queue class is looking like this, I think this one is okay.

class Queue:
    def __init__(self):
        self.lista=[]

    def put(self,x):
        self.lista.append(x)

    def get(self):
        if not len(self.lista)==0:
            return self.lista.pop(0)

    def isempty(self):
        if len(self.lista)==0:
            return True
        else:
            False

    def length(self):
        return len(self.lista)


    def dequeue(self):
        if not len(self.lista)==0:
            n=self.lista.pop(0)
            return n

Aucun commentaire:

Enregistrer un commentaire