Created
November 9, 2015 18:55
-
-
Save dangnhdev/2dbe0d5a6a51247cd95b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org; | |
import java.util.LinkedList; | |
import java.util.Queue; | |
public class Queues { | |
public static <E> Queue<E> split(Queue<E> queue) { | |
Queue<E> myQueue = new LinkedList<>(); | |
if (queue.isEmpty()) { | |
return myQueue; | |
} | |
for (int i = 0; i <= queue.size() / 2; i++) { | |
E item = queue.remove(); | |
myQueue.offer(item); | |
} | |
return myQueue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment