Start New Discussion within our Software Development Community

Firstly, the program used a doubly linked-list which contains ID and NAME lists. Both ID and NAME are parallel. For example, Tony 2456, David 3749, Jessica 9743 and so on.

So I created a method; its function is to remove a specific ID by user input, then it should remove the node which includes both ID and name. Here is my code which seems incorrect. Suggestions?

public static void removeTarget(int IDtarget){
    Node IDfirst = head.IDlink;
    Node IDsecond = head;
    Node NAMEfirst = head.NAMElink;
    Node NAMEsecond = head;
    String NAME;

    if(IDfirst == null || target != IDfirst.id) {
        return;
    }
    else {
        NAME = NAMEfirst.name;
        IDsecond = IDfirst;
        remove(IDsecond.id);
    }

    if(NAME != null) {
        NAMEfirst = NAMEsecond;
        remove(NAME);
    }
}

Ignore the post above. Here's my new problem:

Let's say there are two links that contain name and ID and they are both in parallel. For example, Tony 3461, Jessica 8010, Miranda 4914 and so on.

When one name is removed by user input, its ID must be removed as well. How do I store the position value of the element in the "name" list? So I can remove the ID from the ID link using this value. Here is my method:

if(!(target.equalsIgnoreCase(NAME.head.link.name))) {
            return;
        }
        else {
            if(NAME.head != null) {
                storedint = ID.head.link.id; // store the value of the position
                NAME.head = NAME.head.link; // remove the name
            }
        }

        if(ID.head != null) {
            ID.head.link = storedint; // this line is not working. What I need is to remove the ID in the same position as the NAME.
        }
This article has been dead for over six months. Start a new discussion instead.