Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void partition(T value) {
- Node<T> node = head;
- while (node != null) {
- Node<T> prev = node.previous;
- Node<T> next = node.next;
- if (node.data.compareTo(value) >= 1) {
- // should go to tail
- if (node != tail) {
- prev.next = node.next;
- next.previous = node.previous;
- tail.next = node;
- node.previous = tail;
- node.next = null;
- tail = node;
- }
- } else {
- // should go to head
- if (node != head) {
- prev.next = node.next;
- if (null != next) {
- next.previous = node.previous;
- }
- head.previous = node;
- node.next = head;
- head = node;
- }
- }
- node = next;
- }
- head.previous = null;
- tail.next = null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement