以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 Java/Eclipse 』  (http://bbs.xml.org.cn/list.asp?boardid=41)
----  简单的语法错误  (http://bbs.xml.org.cn/dispbbs.asp?boardid=41&rootid=&id=57172)


--  作者:xsh8hf
--  发布时间:12/25/2007 3:04:00 PM

--  简单的语法错误
public class LList implements ListInterface
{
 private Node firstNode ;//引用第一个节点
        private int length;    //线性表中元素个数
        public LList()
 {
  clear();

 }
 
 public final void clear()
 {
  firstNode=null;
  length=0;
 }

 
 
 private class Node
 {
  private Object data;
  private Node next;
  
  private Node(Object dataPortion)
  {
   data=dataPortion;
   next=null;
  }
  private Node(Object dataPortion,Node nextNode)
  {
   data=dataPortion;
   next=nextNode;
  }
 }


        public boolean add(Object newEntry)
 {
  Node newNode=new Node(newEntry);
  if(isEmpty())
  {
   firstNode=newNode;
  }
  else
  {
   Node lastNode=getNodeAt(length);
   lastNode.next=newNode;
  }

  length++;
  return true;
 
 }

 public boolean add(int newPosition,Object newEntry)
 {
  boolean isSuccessful=true;
  if((newPosition>=1)&&(newPosition<=length+1))
  {
   Node newNode=new Node(newEntry);
   
   if((isEmpty())||(newPosition==1))//
   {
    newNode.next=firstNode;
    firstNode=newNode;
   }
   else
   {
    Node nodeBefore=getNodeAt(newPosition-1);
    Node nodeAfter=nodeBefore.next;
    newNode.next=nodeAfter;
    nodeBefore.next=newNode;
   }
   length++;
  }
  else
   isSuccessful=false;
  return isSuccessful;
  
 }

  private Node getNodeAt(int givenPosition)
  {
   Node currentNode=firstNode;
   for(int counter=1;counter<givenPosition;counter++)
   {
    currentNode=currentNode.next;
   }
   return currentNode;
  }

  public Object remove(int givenPosition)
  {
   Object result=null;
   if(!isEmpty()&&(givenPosition>=1)&&(givenPosition<=length))
   {
    if(givenPosition==1)
    {
     result=firstNode.data;
     firstNode=firstNode.next;
    }
    else
    {
     Node nodeBefore=getNodeAt(givenPosition-1);
     Node nodeToRemove=nodeBefore.next;
     Node nodeAfter=nodeToRemove.next;
     nodeBefore.next=nodeAfter;
     result=nodeToRemove.data;
    }
    length--;
   }
   return result;
  }

  public boolean replace(int givenPosition ,Object newEntry)
  {
   boolean isSuccessful=true;
   if(!isEmpty()&&(givenPosition>=1)&&(givenPosition<=length))
   {
    Node desiredNode=getNodeAt(givenPosition);
    desiredNode.data=newEntry;
   }
   else
    isSuccessful=false;
   return isSuccessful;
  }

  public Object getEntry(int givenPosition)
  {
   Object result=null;
   if(!isEmpty()&&(givenPosition>=1)&&(givenPosition<=length))
   result=getNodeAt(givenPosition).data;
   return result;
  }
  
  public boolean contains(Object anEntry)
  {
   boolean found=false;
   Node currentNode=firstNode;
   while(!found&&(currentNode!=null))
   {
    if(anEntry.equals(currentNode.next))
     found=true;
    else
     currentNode=currentNode.next;
   }
   return found;
  }
      public void display()
 {
  for(int i=length;i>0;i--)
  {
   System.out.println(getNodeAt(i).data);
  }
 }
      public int getLength()
      {

  return this.length;
     }
     public boolean isEmpty()
     {
 return length==0;
     }
     public int getLength()
 {
  return this.length;
 }
     public boolean isFull()
     {
 return false;
     }
     public static void main(String[] args)
 {
  LList Llist = new LList();

  for(int i=0;i<args.length;i++)
  {
   Llist.add(args[i]);
  }
  Llist.display();
 }


}
这个程序有一句语法错误,有没有高手能给我解决一下呢。


--  作者:xsh8hf
--  发布时间:12/26/2007 12:22:00 PM

--  
呜呜呜,没人会吗。。
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
47.119ms