lab4ans - return; Node<E> nodeRef =...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
LAB 4 1. public void add(E element) { if (numElements == 0) { head = new Node<E>(element); head.next = head; } else { Node<E> newNode = new Node<E>(element); newNode.next = head.next; head.next = newNode; } numElements++; } 2. public void display(int index) { if (index < 0) { System.out.println("Invalid index: negative value"); return; } if (numElements == 0)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: return; Node&lt;E&gt; nodeRef = head; for (int i = 0; i &lt; index % numElements; i++) // Advance to starting node nodeRef = nodeRef.next; Node&lt;E&gt; startingNode = nodeRef; do { System.out.print(nodeRef.data); nodeRef = nodeRef.next; } while (nodeRef != startingNode); System.out.println(); }...
View Full Document

Ask a homework question - tutors are online