The problem is here:
while (!(sequence1.isEmpty()))
{
merged.addLast(sequence1.removeFirst());
}
while (!(sequence1.isEmpty()))
{
merged.addLast(sequence2.removeFirst());
}
In your merge function. Both loops check sequence1
for emptiness. Replace the second sequence1
with sequence2
in the loop condition and all will be well.