0

We had been assigned a problem in our Data Structures Laboratory that goes like this:

Fill 4 queues with 10 numbers each(Ranging from 1 through 20).Each number need not be unique,i.e a number may be repeated in a queue.Remove an element from each queue.Say 1,3,11,6 are removed from queues 1,2,3 and 4 respectively.Then find the largest number out of them.Here it is 11.Then find out the queue which gave the smallest number.In this case,it would be 1.Then insert the largest number into the queue from which you obtained the smallest number i.e. add 11 to queue 1.Repeat until you get an empty queue(Multiple queues may be emptied at once).

I used the rand() along with the srand(time(NULL)) function ot insert the numbers into the queues.
The teacher specified what to do when you found two or more equal numbers.I wrote a function but it got too messy.My query is what is the probability that any [A]two of the four numbers removed from the queues would be equal [B]three of the four numbers removed from the queues would be equal ?

If the probability is low enough,I would not have to bother about writing the function to check for equality cases.

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by pyTony
1

Your words about not paying attention to too small probability sounds like famous last words of programmer ;) :(

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.