Android笔试总结(4)

发表于:2013-06-03来源:Csdn作者:xyz_lmn点击数: 标签:Android
this.count = count; } public Node getNextNode() { return nextNode; } publicvoid setNextNode(Node nextNode) { this.nextNode = nextNode; } } ReverseSingleLink.java publicclass ReverseSingleLink { public

  this.count = count;

  }

  public Node getNextNode() {

  return nextNode;

  }

  publicvoid setNextNode(Node nextNode) {

  this.nextNode = nextNode;

  }

  }

  ReverseSingleLink.java

  publicclass ReverseSingleLink {

  publicstatic Node revSingleLink(Node head){

  if(head ==null){ //链表为空不能逆序

  return head;

  }

  if(head.getNextNode()==null){ //如果只有一个结点,当然逆过来也是同一个

  return head;

  }

  Node rhead = revSingleLink(head.getNextNode());

  head.getNextNode().setNextNode(head);

  head.setNextNode(null);

  return rhead;

  }

  publicstaticvoid main(String[] args){

  Node head =new Node(0);

  Node temp1 =null,temp2 =null;

  for(int i=1;i<100;i++){

  temp1 =new Node(i);

  if(i==1){

  head.setNextNode(temp1);

  }else{

  temp2.setNextNode(temp1);

  }

  temp2 = temp1;

  }

  head = revSingleLink(head);

  while(head!=null){

  head = head.getNextNode();

  }

  }

  }

原文转自:http://blog.csdn.net/xyz_lmn/article/details/6922224