method to remove a given node from the list?

Anybody know how to do it?
[33 byte] By [michelle23a] at [2007-10-3 10:18:57]
# 1

Assuming by "list" you mean java.util.List:

java.util.List.remove(int index);

In the event you are referring to javax.swing.JList:

simply manipulate your Object[] or whatever data you are using for your ListData and reassign your List to contain said listData:

javax.swing.JList.setListData(Object[] listData);

(And I am assuming that you're using an Object[] instead of a Vector, which is also usable in said circumstance)

And, finally, if you are using the java.awt.List:

java.awt.List.remove(int position);

java.awt.List.remove(String item);

Navy_Codera at 2007-7-15 5:40:04 > top of Java-index,Java Essentials,New To Java...
# 2

import java.util.Iterator;

import java.util.HashSet;

import java.util.Set;

/**

* A doubly linked list as introduced in lecture 6 in IN2002. Template for

* coursework 2a in 2006.

*/

public class DLList implements Iterable {

/**

* Inner class for doubly linked list nodes.

*/

class DLNode {

Object info; // the data element

DLNode next; // the next node

DLNode prev; // the previous node

DLNode(Object argInfo) {

info = argInfo;

}

}

private DLNode head, tail;

private int count;

/**

* Appends an object at the tail of this list.

* @param argOb The object to append.

*/

public void appendAtTail(Object argOb) {

DLNode node = new DLNode(argOb); // new node

if (tail == null) { // empty list

tail = node;// set the tail

head = tail;// and head

} else {// non-empty list

tail.next = node; // connect the

node.prev = tail;// new node

tail = node;// set the tail

}

count++;// udpate count

}

/**

* Deletes the given node maintaining the list structure.

* @param node The node to delete, must be in the list.

*/

private void delete(DLNode node) {

..............................?

..............................?

michelle23a at 2007-7-15 5:40:04 > top of Java-index,Java Essentials,New To Java...
# 3
Hi,Sorry but we won't solve your homework. Do you have a specific question? Do you need some help? What is it that you need help with?Kaj
kajbja at 2007-7-15 5:40:05 > top of Java-index,Java Essentials,New To Java...
# 4

take the head value of the node you want to delete and set it equal to the head node's tail.

take the tail value of the node you want to delete and set it equal to the tail node's head.

So that this:

H<>D<->T

Becomes this:

H<>T

Nothing refers to the D node, so it's eligible for GC.

%

duffymoa at 2007-7-15 5:40:05 > top of Java-index,Java Essentials,New To Java...
# 5
Sorry, I got it wrong in writing. The picture is correct.take the delete node's tail and set it equal to the head node's tailtake the delete node's head and set it equal to the tail node's head.pictures help. draw some.%
duffymoa at 2007-7-15 5:40:05 > top of Java-index,Java Essentials,New To Java...