Vikings1201 0 Newbie Poster

I am trying to complete a circular linked list add method but I am having difficulty understanding how to. I wrote the above link list add method.

I know that a circular linked list, somewhat.

Here is what the add function is suppose to do: Any suggestion on how to do this or anything would grately help.

// Add a new item to the list. The added item should be placed
// after the item referenced by the cursor, and the cursor
// should be then advanced. Consequently, after adding, the
// cursor will point to the new item, and subsequent adds will
// put the item after the previously added item.
public void add(E elem);

public void add(int index, E dataItem)  throws ListOutOfBoundsException
	{
		if (index >= 1  &&  index <= numItems+1)
		{
			numItems++;
			if ( index == 1 )
				// insert new node at beginning of list
				head = new Node<E>(dataItem, head);
			else
			{
				Node<E> prev = find(index-1);
				
				// insert new node after the node that prev references
				Node<E> newNode = new Node<E>(dataItem, prev.getNext());
				prev.setNext(newNode);
			}
		}
		else
			throw new ListOutOfBoundsException("Index out of bounds on add");
	}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.