JAVA 问题 高手进入, 谢谢了

来源:百度知道 编辑:UC知道 时间:2024/06/02 10:00:53
最近快考试了,在做大量卷子,有不少题目不会,高手指教,谢谢了.请别在意分数,因为有不少题目要问,所以没多少了........

a) Given the following interface for a List, write a mthod that checks to see if a given object is present in a given list. The method accepts a List and an Object as parameters. The method should return true if the object is equal to one of the items in the list, and false if none of the items in the list is equal to the object.

public interface List {
public bollean isEmpty();
public int size();
public void add(Object o, int index);
public void remove(int index);
public Object get(int index);
public void removeAll();
}

public bollean contains(List 1, Object o){
在这里接着写,谢谢了

b)What would the big-O running time of your method be if the List was implemented using an array?

c) What would the big-O running time of your method be if the List was implemented using a DoubleLinkedList?

下面的书写有误:bollean 应该是Boolean
public Boolean contains(List l, Object o){
Boolean isequal = false;
for(int i=0;i<l.size();i++)
{
if(l.get(i).equals(o))
{
isequal = true;
}
}
return isequal;


b:
public class array implements List
{
private Object[] elementData;
private int size;
public Boolean isEmpty();
{
return size==0;
}
public int size()
{
return this.size;
}
public void add(Object o, int index)
{
this.elementData[index] = o;
this.size += 1;
}
public void remove(int index)
{
this.elementData[index] = null;
}
public Object get(int index)
{
return this.elementData[index];