class List{private classNode
{privateT data;privateNode next;privateNode(T data)
{if(data != null)this.data =data;
}private voidadd(T data)
{if(this.next == null)this.next = newNode(data);else
this.next.add(data);
}private void remove(Node previous, intindex)
{if(List.this.foot++ ==index)
{
previous.next= this.next;this.next = null;
List.this.count--;return;
}else{this.next.remove(this,index);
}
}private voidremove(Node previous, T data)
{if(this.data.equals(data))
{
previous.next= this.next;this.next = null;
List.this.count--;return;
}if(this.next != null)this.next.remove(this,data);else
return;
}private void replace(intindex, T data)
{if(List.this.foot++ ==index)this.data =data;else
this.next.replace(index,data);
}private voidreplace(T oldData, T newData)
{if(this.data.equals(oldData))this.data =newData;else
this.next.replace(oldData,newData);
}private T get(intindex)
{if(List.this.foot++ ==index)return this.data;else
return this.next.get(index);
}privateboolean contains(T data)
{if(this.data.equals(data))return true;if(this.next != null)return this.next.contains(data);else
return false;
}
}//===============================================
privateNode root;private intcount;private intfoot;publicList()
{}publicboolean isEmpty()
{if(this.count == 0 && this.root == null)return true;else
return false;
}public intsize()
{return this.count;
}public voidadd(T data)
{if(this.isEmpty())this.root = newNode(data);else
this.root.add(data);this.count++;
}public void remove(intindex)
{if(this.isEmpty())return;if(index < 0 || this.count <=index)return;if(index == 0)
{
Node temp= this.root;this.root = this.root.next;
temp.next= null;this.count--;return;
}else{this.foot = 0;this.root.remove(this.root, index);
}
}public voidremove(T data)
{if(this.isEmpty())return;if(this.root.data.equals(data))
{
Node temp= this.root;this.root = this.root.next;
temp.next= null;this.count--;return;
}else{this.root.next.remove(this.root, data);
}
}public void replace(intindex, T data)
{if(this.isEmpty())return;if(index < 0 || this.count<=index)return;this.foot = 0;this.root.replace(index,data);
}public voidreplace(T oldData, T newData)
{if(this.isEmpty())return;this.root.replace(oldData,newData);
}public T get(intindex)
{if(this.isEmpty())return null;this.foot = 0;return this.root.get(index);
}publicboolean contains(T data)
{if(this.isEmpty())return false;return this.root.contains(data);
}publicObject[] toArray()
{if(this.isEmpty())return null;int count = this.count;
Object[] retVal= newObject[count];for(int i = 0; i < count; i++)
{
retVal[i]= this.get(i);
}returnretVal;
}
}public classHello
{public static voidmain(String[] args) throws Exception
{
List myList = new List();
myList.add("Hello");
myList.add("world");
myList.add("Ni");
myList.add("Hao");
myList.add("HeHe");
System.out.println(myList.contains(null));
Object[] result=myList.toArray();for(Object item : result)
{
String temp=(String)item;
System.out.println(temp);
}
}
}