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.