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;
}
}
}
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;
}
}
}
大概改了下 求楼主给分
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;
}
}
}