I find that this problem is interesting. When we discuss about queue, it's not always strict queue rule that we have in mind. Sometimes people can just cut the line because they know someone in the line.
The idea of solving is using list of queue.
- Each time an element comes, check each list member which is a queue.
- If the queue.front() 's team is the same with the new element, just push it to the queue
- else check other member of the list
- if there is no element with the same team, create new queue in the back of the list
No comments:
Post a Comment