How can I add an element to a double linked list after inserting?
<p>How can I add elements in a node after inserting? It must to add to the first and the last list. The structure is DoubleLinked List. Have a class node:</p>

<pre><code>class Node
 {
    Node next;
    Node prev;
    int data;

 void setData(int v)
    {
     data = v;
    }

 void setNext(Node n)
    {
     next = n;
    }

 int getData()
    {
     return data;
    }

 Node getNext()
    {
     return next;
    }

 void setPrev(Node n)
    {
     prev = n;
    }

 Node getPrev()
    {
     return prev;
    }
 }
</code></pre>

<p>And from DoubleLinked list</p>

<pre><code>class DLinkedList
{
Node first;
Node last;
 public void insert(int v)
    {
     Node p = new Node();
     p.setData(v);
     if(first == null)
     {
         p.setPrev(null);
         first = p;
         last = p;
     }  
     else
     {
         Node q = first;
         while(q.getNext() != null)
         {
             q = q.getNext();
         }   
         q.setNext(p);
         p.setPrev(q);
         last = p;
     }
    }
 }
</code></pre>
