Is This Double Linked Function Correct??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • babynailah
    New Member
    • Sep 2006
    • 7

    #1

    Is This Double Linked Function Correct??

    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]
  • doelf
    New Member
    • Oct 2006
    • 9

    #2
    Originally posted by babynailah
    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]

    Write a JUnit-Test and you know the answer. - But it would be better to write the JUnit-Test first, then implement the class and if the test is running fine the problem is terminated.

    Comment

    Working...