element at index in a circular linked list
<p>I was reading about circular linked lists. Here is a code which I do not understand how it works.</p>

<pre><code>public int elementAt(int index){
        if(index&gt;size){
            return -1;
        }
        Node n = head;
        while(index-1!=0){ // this line is unclear for me
            n=n.next;
            index--;
        }
        return n.data;
    }
</code></pre>

<p>I would write the same code but in this way :</p>

<pre><code>public int elementAt(int index){
        if(index&gt;size){
            return -1;
        }
        Node n = head;
        while(n.size != index){ // here is my change in the code
            n=n.next;
        }
        return n.data;
    }
</code></pre>

<p>Here is the whole code : <a href="http://algorithms.tutorialhorizon.com/circular-linked-list-complete-implementation/" rel="nofollow">http://algorithms.tutorialhorizon.com/circular-linked-list-complete-implementation/</a></p>

<p>Am I doing right in the second code  ?</p>

<p>Thanks</p>