Hi guys,
I am new to java and I need to create a a singly linked circular list in java with the following methods:
insert new node, delete node, get next node, get first node and create empty list.
Here is what I have so far and I am not sure if I am on the right track or not? Your help will be much appreciated. Thank you in advance!
public class SingleLinkedCircularL
{
public class Link
{
int item=0;
Link next;
public Link()
{
//this.item = 0;
Link next = null;
}
public Link(int i, Link n)
{
item = i;
next = n;
}
}
Link head;
public void insert(int item)
{
if(head == null)
{
head = new Link(item,null);
head.next = head;
}
else
{
head.next = new Link(item,head.next);
}
}
public void remove(int key)
{
Link current = head;
do
{
if(current.next.item == key )
{
Link temp = current.next;
current = temp.next;
if(temp == head)
{
head = head.next;
}
temp = null;
break;
}
current = current.next;
} while(current != head);
}
public static void step(Link current)
{
current= current.next;
}
public static void main(String args[]) {
}
}