我必须使用interface在List中编写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
有效)
N0
位置得到节点index-1
N1
位置得到节点index
。Nn
创建新节点(N0, N1, obj)