码迷,mamicode.com
首页 > 其他好文 > 详细

单链翻转

时间:2018-11-17 19:26:11      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:htm   while   blog   输入   html   bsp   turn   输出   reverse   

有看到用c++实现的 :http://www.cnblogs.com/venow/archive/2012/08/26/2657559.html


输入单链:1->2->3->4->5

输出:      5->4->3->2->1

 

public Node reverse (Node node){

  Node curNode = node;
  Node storeNode = null;

  while (curNode != null) {

    Node nextNode = curNode.next;

    curNode.next = storeNode;

    storeNode = curNode;

    if (nextNode != null){

      curNode = nextNode;

    }        

  }

  return storeNode;

}

单链翻转

标签:htm   while   blog   输入   html   bsp   turn   输出   reverse   

原文地址:https://www.cnblogs.com/Jennifer-fang/p/9974777.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!