littleghost76 0 Newbie Poster

The assignment is to write a circular linked list. I know that it is pretty much the same thing as a singly linked list but with the head pointing to itself instead of null. however i am not sure if i did this right or not... or if my add and remove methos are alright.
and if someone could please, please help me with my find method, it would be awesome!

thanks a lot
Val.

(here goes my code)

public class CircularLinkedList
{
    private Link head;
    private int counter;
        
    public void LinkList()
    {
    head.next = head;
    }
    
    public boolean isEmpty()
    {
    return (head == null);
    }
    
    public void insert(int id)
    {
    Link newLink = new Link(id);
    newLink.next = head;
    head = newLink;
    counter++;
    }
    
    public Link delete()
    {
    Link temp = head;
    head = head.next;
    return temp;
    }
    
    public boolean find(int id)
    {
    Link x = head;
    Link value = new Link(id);
    boolean found = false;
    
    for(int i = 0; i < counter; i++)    
        {
        x = x.next;
        if(x == value)
            found = true;
       }
    System.out.println(found);
    return found;
    }
    
    public void displayList()
    {
    System.out.println("List from first to last: ");
    Link current = head;
    while(current != null)
        {
        current.displayLink();
        current = current.next;
        }
    System.out.println("");
    }
}
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.