public static <T> pnode_t<T> copy_postings_list(pnode_t<T> L) {
    // Return empty list if L is nullptr.
    if (L == null) {
      return null;
    }

    // 1st stage: Copy the nodes from L.
    pnode_t<T> p = L;
    while (p != null) {
      pnode_t<T> temp = new pnode_t<T>(p.data, p.next, null);
      p.next = temp;
      p = temp.next;
    }

    // 2nd stage: Update the jump field.
    p = L;
    while (p != null) {
      if (p.jump != null) {
        p.next.jump = p.jump.next;
      }
      p = p.next.next;
    }

    // 3rd stage: Restore the next field.
    p = L;
    pnode_t<T> copied = p.next;
    while (p.next != null) {
      pnode_t<T> temp = p.next;
      p.next = temp.next;
      p = temp;
    }
    return copied;
  }