public class NodeTest1 {
public NodeTest1() {
// TODO Auto-generated method stub
 Node1 head=null;
for(int i=0;i<5;i++)
{
String str=String.valueOf(i);
head=new Node1(str,head);
}
}

private Node1 findmidList(Node1 head)
{

if(head==null||head.next==null)
return head;
Node1 probe1=head;
Node1 probe2=head;
while(true)
{
if(probe1.next!=null&&probe1.next.next!=null)
{
probe1=probe1.next.next;
probe2=probe2.next;
}
else
break;


}
return probe2;



}
public static void main(String args[])
{
NodeTest1 node=new NodeTest1();
node.findmidList(head);
}




private class Node1
{
private Object value;
private Node1 next;
private Node1()
{
this.value=null;
this.next=null;
}
private Node1(Object value,Node1 next)
{
this.value=value;
this.next=next;
}


}
}

解决方案 »

  1.   

    首先楼主创建的head代表不是指针而是那个点。其次如果需要头结点信息,可以改写NODETest1将其设置一个返回值,传个一个NODE1即可,楼主为什么喜欢去实现一个无用的类NODETest1呢?将构造函数NODETes1改成一个普通方法吧
    大概改了下 求楼主给分
    public class NodeTest1 {
    Node1* public CreateNodesequence() {
    // TODO Auto-generated method stub
    Node1 head=null;
    for(int i=0;i<5;i++)
    {
    String str=String.valueOf(i);
    head=new Node1(str,head);
    }
    }private Node1 findmidList(Node1* head)
    {if(head==null||head.next==null)
    return head;
    Node1 probe1=head;
    Node1 probe2=head;
    while(true)
    {
    if(probe1.next!=null&&probe1.next.next!=null)
    {
    probe1=probe1.next.next;
    probe2=probe2.next;
    }
    else
    break;
    }
    return probe2;}
    public static void main(String args[])
    {
    Node1* head=new CreatNodesequence();
    node.findmidList(head);
    }
    private class Node1
    {
    private Object value;
    private Node1 next;
    private Node1()
    {
    this.value=null;
    this.next=null;
    }
    private Node1(Object value,Node1 next)
    {
    this.value=value;
    this.next=next;
    }
    }
    }