<commit_before>package linked_list;

import datastructures.lists.CustomLinkedList;
import datastructures.lists.LinkedListNode;

public class MoveAllOccurancesToEnd {

  private CustomLinkedList<Integer> linkedList = null;

  public void constructLinkedList(String input) {
    linkedList = new CustomLinkedList<Integer>();
    String[] elements = input.split(" ");

    for (String e : elements) {
      if (e != null && !e.trim().isEmpty()) {
        linkedList.add(Integer.parseInt(e.toString()));
      }
    }
  }

  public CustomLinkedList<Integer> moveAllOccurancesToEnd(int key) {
    LinkedListNode<Integer> head = linkedList.head();
    LinkedListNode<Integer> tail = linkedList.tail();

    while ((head = linkedList.head()).data == key) {
      linkedList.head(head.next);
      head.next = null;
      linkedList.tail().next = head;
      linkedList.tail(head);
    }
    
    LinkedListNode<Integer> current = head;
    LinkedListNode<Integer> runner = current.next;

    while (!runner.equals(tail)) {
      int data = runner.data;
      if (data == key) {
        current.next = runner.next;
        runner.next = null;
        linkedList.tail().next = runner;
        linkedList.tail(runner);
        runner = current.next;
      } else {
        current = current.next;
        runner = runner.next;
      }
    }

    return linkedList;
  }
}<commit_msg>Add question<commit_after>package linked_list;

import datastructures.lists.CustomLinkedList;
import datastructures.lists.LinkedListNode;

/**
 * Question:
 * http://www.geeksforgeeks.org/move-occurrences-element-end-linked-list/
 * 
 * @author <NAME>
 */
public class MoveAllOccurancesToEnd {

  private CustomLinkedList<Integer> linkedList = null;

  public void constructLinkedList(String input) {
    linkedList = new CustomLinkedList<Integer>();
    String[] elements = input.split(" ");

    for (String e : elements) {
      if (e != null && !e.trim().isEmpty()) {
        linkedList.add(Integer.parseInt(e.toString()));
      }
    }
  }

  public CustomLinkedList<Integer> moveAllOccurancesToEnd(int key) {
    LinkedListNode<Integer> head = linkedList.head();
    LinkedListNode<Integer> tail = linkedList.tail();

    while ((head = linkedList.head()).data == key) {
      linkedList.head(head.next);
      head.next = null;
      linkedList.tail().next = head;
      linkedList.tail(head);
    }

    LinkedListNode<Integer> current = head;
    LinkedListNode<Integer> runner = current.next;

    while (!runner.equals(tail)) {
      int data = runner.data;
      if (data == key) {
        current.next = runner.next;
        linkedList.tail().next = runner;
        runner.next = null;
        linkedList.tail(runner);
        runner = current.next;
      } else {
        current = current.next;
        runner = runner.next;
      }
    }

    return linkedList;
  }
}
{'fraction_non_alphanumeric': 0.12850140056022408, 'fraction_numerical': 0.0, 'mean_word_length': 2.8870748299319726, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7148456', 'n_tokens_mistral': 864, 'n_tokens_neox': 837, 'n_words': 169}