>我必须使用界面在列表中对 add 方法进行编码。 我试过了,但它甚至不起作用。 谁能帮我。 接口和列表类给出如下:
/**
* Inserts the specified element at the specified position in this list.
* Shifts the element currently at that position (if any) and any subsequent
* elements to the right (adds one to their indices).
* @param index Index at which to add
* @param obj The object to add
* @return True if insertion was successful
*/
public boolean add(int index, Token obj) {
// implement this
}
假设你有一个双链表,其中包含如下节点(previous-node, next-node, stored-object)
:
伪代码(仅对index>0
和index<list.size
有效(
-
获取
index-1
位置的节点N0
-
获取
index
位置的节点N1
。 -
使用
(N0, N1, obj)
创建新的节点Nn
-
将
N0
next-node
更新为Nn
-
将
N1
previous-node
更新为Nn
-
返回 true。