Skip to content

Instantly share code, notes, and snippets.

@dangnhdev
Created November 9, 2015 18:51
Show Gist options
  • Save dangnhdev/41b08e4d282b127242b0 to your computer and use it in GitHub Desktop.
Save dangnhdev/41b08e4d282b127242b0 to your computer and use it in GitHub Desktop.
/*
* 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