Created
November 9, 2015 18:51
-
-
Save dangnhdev/2d55b4a8c1f5b19ee222 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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package org; | |
import java.util.LinkedList; | |
import java.util.Queue; | |
/** | |
* | |
* @author 404NotFound | |
*/ | |
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