First of all, I'm a total beginner which is the reason that probably my code contains a few simple and dumb mistakes...but how you see I'm working on it ;)
My task is to write a program that contains a queue which will be returned in reversed order. But my problem is that some restrictions are made and at this moment I'm totally confused :( Maybe someone can help me a little.
Two functions are given:
def enqueue(self,z,q): # z is an element, q = queue return q.append(z) def dequeue(self,q): return q.pop(0)
Further I'm only allowed to use one variable to buffer one element of queue. Calling len(q) and using controlvariables and parameters within loops is permitted.
So here is my sourcecode:
class Queue: def __init__(self): self.z = "" self.q =  def enqueue(self,z,q): return q.append(z) def dequeue(self,q): return q.pop(0) def queueReverse(q): n = 1 print len(q) for x in range(len(q)-2): for x in range((len(q)-1)-n): enqueue(dequeue(q),q) a = dequeue(q) for x in range(n): enqueue(dequeue(q),q) enqueue(a,q) n += 1 enqueue(dequeue(q),q) return q #--------------- main ---------------- test = Queue() q = [1,2,3,4,5,6,7] test.queueReverse() print q
So, in advance, thanx a lot!