Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

add node between two node?

i have another question if i want two add node between two node in doubly linked list

add between is my method if i have two add method one for first and one for second what i shall do in my add between method

import java.util.NoSuchElementException;

public class DoublyLinkedListImpl<E> {

private Node head;

private Node tail;

private int size;

public DoublyLinkedListImpl() {

size = 0;

}

/**

* this class keeps track of each element information

* @author java2novice

*

*/

private class Node {

E element;

Node next;

Node prev;

public Node(E element, Node next, Node prev) {

this.element = element;

this.next = next;

this.prev = prev;

}

}

/**

* returns the size of the linked list

* @return

*/

public int size() { return size; }

/**

* return whether the list is empty or not

* @return

*/

public boolean isEmpty() { return size == 0; }

public E getFirstt()

{

return head.element;

}

public E getLast()

{

return tail.element;

}

/**

* adds element at the starting of the linked list

* @param element

*/

private void addBetween(Node e1, E elem, Node e2) {

prior.add(elem);

}

2 Answers

Relevance
  • ?
    Lv 7
    4 years ago
    Favorite Answer

    Normally referred to as "insertion."

  • 4 years ago

    Doop-doo do-woooohhh

Still have questions? Get your answers by asking now.