Merge k sorted array heap problem what is wrong with this code?

i am not able to find error in my code what is wrong with my code dose my logic wrong ? https://ide.codingblocks.com/s/117363

@bishtmanish786 Your logic is wrong somewhere. Not processing all the elements correctly.
Have a look at this simple implementation https://ide.codingblocks.com/s/117015

@pratyush63 sir i understood this concept but i also used similar logic in my code . in my code i used array of queue instead of 2d array in this array i stored address of each queue . then i insert first element of each queue to min heap and then top element of heap inserted into output array. after inserting into output array i poped first element of each queue.
then i search min element rest of queue and insert it into min heap .once i found min of all queue i poped that element from that queue and then insert it into the min heap .

sir you also suggest me similar algorithm but what i am doing wrong here . https://ide.codingblocks.com/s/117363

@bishtmanish786 You were not handling the cases when a queue goes empty.
Check the modified code and read the comments:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like