<commit_before>// Doubly Linked lists

/*
Difference between a doubly linked list and a normal Linked list is that
we now have a double link: one for the next element and one for the previous
one.
*/

function DoublyLinkedList(){
  function Node(element){
    this.element = element;
    this.next = null;
    this.prev = null;
  }

  var head = null,
      tail = null,
      length = 0;
  
}<commit_msg>add insert method for doubly linked list<commit_after>// Doubly Linked lists

/*
Difference between a doubly linked list and a normal Linked list is that
we now have a double link: one for the next element and one for the previous
one.
*/

function DoublyLinkedList(){
  function Node(element){
    this.element = element;
    this.next = null;
    this.prev = null;
  }

  var head = null,
      tail = null,
      length = 0;

  this.insert(element, position){
    if (position >= 0 && position <= length){
      var node = new Node(element),
          current = head,
          previous,
          index = 0;

      if (position === 0){
        if (!head) {
          head = node;
          tail = node;
        } else {
          node.next = current;
          current.prev = node;
          head = node;
        }
      } else if (position === length) {
          current = tail;
          current.next = node;
          node.prev = current;
          tail = node;
      } else {
        while (index++ < position){
          previous = current;
          current = current.next;
        }
        node.next = current;
        previous.next = node;

        current.prev = node;
        node.prev = previous;
      }
      length++;
      return true;
    } else {
      return false;
    }
  };



}
{'fraction_non_alphanumeric': 0.09941520467836257, 'fraction_numerical': 0.0029239766081871343, 'mean_word_length': 1.8141447368421053, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5818150', 'n_tokens_mistral': 498, 'n_tokens_neox': 477, 'n_words': 174}