Hi, I have a program that deals with stacks and queues in python. Part of the program compares items in 3 stacks that contain objects. The loop will run and compare all items in the top of the stacks and pop the item that has the highest value and appends to a queue.
The problem I am haveing right now is the best way to set up my conditional while loop to have the block of code keep running untill all 3 stacks are empty of objects. Currently the loop ends as soon as one of the stacks become empty of objects.
Whats the best way to do a multi way decision to make sure my loop continues to run untill ALL stacks are empty.
Here is a snippit of the code thats giving me issues.
Runway1-3 are my stacks, and they are being added to runway4 which is my queue depending on which airplane object has the highest number of passengers. Currently the comparison part of my code seems to be working correctly but the top while loop that runs the whole block of code untill the stacks are empty is whats giving me issues. Its ending as soon as 1 stack becomes empty, not all three.
def makeRunwayQueue(runway1, runway2, runway3):
runway4 = makeQueue()
while len(runway1) > 0 and len(runway2) > 0 and len(runway3) > 0:
run1Plane = top(runway1)
topPassenger1 = run1Plane.getNumOfPassengers()
run2Plane = top(runway2)
topPassenger2 = run2Plane.getNumOfPassengers()
run3Plane = top(runway3)
topPassenger3 = run3Plane.getNumOfPassengers()
if topPassenger1 > topPassenger2 and topPassenger1 > topPassenger3:
popPlane = pop(runway1)
runway4.append(popPlane)
elif topPassenger2 > topPassenger1 and topPassenger2 > topPassenger3:
popPlane = pop(runway2)
runway4.append(popPlane)
else:
popPlane = pop(runway3)
runway4.append(popPlane)
return runway4