FOR THE CELL PHONE NUMBERS THAT ARE ALEADY STORED ..I HAVE TO CREATE A LINKED LIST TO VIEW THE NUMBERS AND IT HAS TO BE VIEWED IN THE TEXTAREA...IS THIS CODE RIGHT??
Code:
public class DoubleLink1 implements CellPhoneShell
{
private NodeData head;
private NodeData tail;
public DoubleLink1()
{
this.tail = null;
this.head = null;
}
public void add(Contact data)
{
NodeData newNode = new NodeData(data);
if(head != null)
{
newNode.next = head;
head.prev = newNode;
head = newNode;
}
else
{
head = tail = newNode;
}
}
public Contact retrieve(String name)
{
NodeData current = head;
while(current !=null)
{
if(current.data.getName().equals(name))
return current.data;
current = current.next;
}
return null;
}
public void traverse()
{
NodeData current = head;
while(current !=null)
{
(current.getData());
current = current.next;
}
}
public boolean isEmpty(String name)
{
NodeData current = head;
NodeData previous = head.prev;
NodeData next = head.next;
boolean found = false;
if (head == null)
return false;
while(current != null)
{
if(current.data.getName().equals(name))
{
found = true;
return found;
}
previous = current;
current = current.next;
if (current != null)
next = current.next; }
if (found)
{
if (previous == null)
head = head.next;
else if (next == null)
tail = tail.prev;
else {
previous = current.next;
next = current.prev;
}
}
return found;
}
}END OF DOUBLE LINK CLASS[I] [/I]
Comment