public class LinkedListRevert {
public static void main(String[] args) { Node next3 = new Node(4,null);
Node next2 = new Node(3,next3);
Node next = new Node(2,next2);
Node head =new Node(1,next); Node tmp = head; // 保存首节点
while (head!=null){ System.out.println(head.value);
head=head.next;
}
Node revertHead = revert(tmp); while (revertHead!=null){ System.out.println(revertHead.value);
revertHead=revertHead.next;
}
} public static Node revert(Node head){ Node prev = null;
Node next = head.next; while(head!=null){
next = head.next;
head.next = prev;
prev = head;
head = next;
}
return prev;
}
} class Node{
int value;
Node next;
public Node (int value,Node next){
this.value = value;
this.next = next;
}
}

Java ---- 链表逆序的更多相关文章

  1. 链表逆序(JAVA实现)

    题目:将一个有链表头的单向单链表逆序 分析: 链表为空或只有一个元素直接返回: 设置两个前后相邻的指针p,q,使得p指向的节点为q指向的节点的后继: 重复步骤2,直到q为空: 调整链表头和链表尾: 图 ...

  2. 链表逆序,java实现

    package com.cskaoyan.linkedlist; //反转数组 public class LinkedListDemo2 { public static Node reverse(No ...

  3. Reverse Linked List II 单向链表逆序(部分逆序)

    0 问题描述 原题点击这里. 将单向链表第m个位置到第n个位置倒序连接.例如, 原链表:1->2->3->4->5, m=2, n =4 新链表:1->4->3-& ...

  4. ZT 链表逆序

    链表逆序 原帖地址http://blog.csdn.net/niuer09/article/details/5961004 分类: C/C++2010-10-23 17:23 18425人阅读 评论( ...

  5. C# 单向链表 逆序(递归)

    static void Main(string[] args) { while (true) { LinkedList L = new LinkedList(); L.Add(new Node(&qu ...

  6. 链表逆序---python

    class ListNode: Value = '' # 节点要储存的值,因为Python是弱类型,因此无需传入泛型 Next = None # 下一个节点,初始化时为空值 def __init__( ...

  7. 【云栖社区001-数据结构】如何实现一个高效的单向链表逆序输出(Java版)

    如题 动手之前,发现自己很擅长用C语言来写链表. 不过,既然自己做的是Java开发,那么还是用Java实现这个算法吧:毕竟,以后的若干年里都差不多要跟Java打交道了. 于是,先将Java版的链表自学 ...

  8. 剑指Offer03 逆序输出链表&链表逆序

    多写了个逆序链表 /************************************************************************* > File Name: ...

  9. 基于visual Studio2013解决面试题之0504单链表逆序

     题目

随机推荐

  1. PCP

    1, What is PCP?Prior Comparable Period2, Why needs PCP?This is to compare the value with history val ...

  2. python中sys模块之输入输出错误流

    import sys sys.stdout.write("msg")   # 控制台白色字体打印 普通输出流 sys.stderr.write("msg") # ...

  3. 设计一个字符串类String(C++练习题)

    要求:设计一个字符串类String,可以求字符串长度,可以连接两个串(如,s1=“计算机”,s2=“软件”,s1与s2连接得到“计算机软件”),并且重载“=”运算符进行字符串赋值,编写主程序实现:s1 ...

  4. Vue源码之目录结构

    Vue版本:2.6.9 源码结构图 ├─ .circleci // 包含CircleCI持续集成/持续部署工具的配置文件 ├─ .github // 项目相关的说明文档,上面的说明文档就在此文件夹 ├ ...

  5. 使用日期操作类(Calendar)获得几秒、几分钟、几小时之前的时间

    public String dealDate(String case_time){ // 日期操作类 Calendar calendar = Calendar.getInstance(); // 当前 ...

  6. RESTful Levels & HATEOAS

    什么是RESTful REST这个词,是Roy Thomas Fielding在他2000年的博士论文中提出的.翻译过来就是"表现层状态转化.” REST是一种软件架构风格.设计风格,而不是 ...

  7. STM32L071CBTX操作ECC508

    因为我是在stm32上面做的加密操作,所以我只对stm32的方案做总结. 1.ATECC508的底层接口是i2c的,工程中跟i2c相关的操作放在文件hal_stm32l0_ateccx08_i2c.c ...

  8. Postman 使用方法详解

    转自:https://blog.csdn.net/fxbin123/article/details/80428216 一.Postman背景介绍 用户在开发或者调试网络程序或者是网页B/S模式的程序的 ...

  9. centos 安装 crontab 和 简单的使用教程

    crontab是一个非常好用的定时执行任务的程序.以下是操作方式 1. 安装 cron 的 主程序 : yum -y install vixie-cron 2. 安装 cron 守护进程的表格的程序  ...

  10. python3 多线程爆破ftp、mysql、ssh

    当然 也支持ip 为 127.0.0.1-255 这样的 字典放到 dict 目录里 链接: https://pan.baidu.com/s/1htchOyN5hK9nmZlWfTiFzA 密码: v ...