I have the template for a linked list and I am trying to turn it into a circular doubly linked list in java
<p>I'm trying to turn a linked list into a circular doubly linked list and I'm having some trouble doing so with a bunch of different methods in my linked list class, for example I don't know how to change the writeList() method this is what it looks like right now</p>

<pre><code>public void writeLinkedList() {
    Node p, q;
    System.out.println("Writing list:");
    for (p = listStart, q = null; p != null; q = p, p = p.getNext());

    for (p = listStart; p != q; p = p.getNext())
        System.out.println(p.getData());
}
</code></pre>

<p>Im using the first for loop to identify q as the last node in the list, I'm not sure how to go further with this.
My node class is posted below aswell</p>

<pre><code>public int getData() {
    return data;
}

public Node getNext() {
    return next;
}

public Node getPrev(){
    return prev;
}
//Mutators
public void setData(int x) {
    System.out.println("inside setData");
    data = x;
}

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

public void setPrev(Node p){
    prev = p;
}
</code></pre>