You should work on usual formatting issues.
So the fix as I understood is to build a hierarchy of queues by setting the parent member. Then find the parent that has maxCapacity set, and verify it is not exceeded. Sounds like the right approach.
Do you need to update the current capacity for the parent, when you allocate new slots for a child queue?