[code=Java][/code]
public interface MyList {
public void add(Object o);
public void add(int index,Object o); // 添加元素
public void clear();
public boolean contains(Object o);
public Object get(int index);
public int indexOf(Object o);
public boolean isEmpty();
public int lastIndexOf(Object o);
public boolean remove(Object o);
public Object remove(int index);
public Object set(int index,Object o);
public int size();
public int getSection(String o); // 获得元素的位置
public Object getElement(Object o); // 获取某位置的元素
public void setElement(Object o); // 修改该处的元素
}
这个是接口
有必要的地方我都加注释了
------解决方案--------------------
MyLinkedList.java里面的
- Java code
public int getSection(String s) { int n = -1; Node current = first; while (n < size) { if (current.element == s) { n++; break; } else { current = current.next; n++; } } return n; }