Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. Hi Daniel, looks like you've been busy then! Okay so the way you're trying to merge is by creating a new ArrayQueue and populating it. That's good. This task is a little bit complex. Your loop can basically be conditional on either/both q1 or q2 still having elements. The sequence is that if q1 has no elements then dequeue q2 and enqueue it to the new queue, then vice versa for q2. So these are the top level ones so that on each loop you are just putting them back in the order they already existed in because it doesn't need changing. That make sense? The problem part is checking the order. But you just get the first element, then compare it with the first element of the other queue to be merged. This will find out which queue to dequeue. Here's a hint to how compareTo() works: in x.compareTo(y) a less than 0 value means that x is less than y in their ordering. A 0 value means the same order, but in this case it wouldn't matter which way you put them. Greater than 0 means x is after y in the ordering. So what you have is close to what I described in terms of comparing, you just need to use the correct method to get the first element. But for the enqueueing while sorting you haven't got it right because you're adding 2 elements on every loop, just the order changes, when you can't be sure that next element in the resultant queue will be from the other queue. Hope that helps.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement