遍历,一共有三种情况,

1. pre <= x <= current

2. 遍历到了head时,x>tail 或者 x<=head (不会等于tail)

3. 遍历回aNode或同值的Node,此时直接插到此Node的前面

public void insert(Node aNode, int x) {
  ListNode last = aNode;
  ListNode current = aNode.next;
  while (current.val != aNode.val) {
    if(last.val<=x && x<=current.val) {
      insertbtw(last,current,x);
      return;
    }
    else {
      if (last.val>current.val && (last.val<x || x<=current.val)) {
        insertbtw(last,current,x);
        return;
      }
    }
    last = current;
    current = current.next;
  }
  if(!inserted) {
    insertbtw(last,current,x);
  }
  return;
}

public void insertbtw(ListNode last, ListNode current, int x) {
  ListNode temp = new ListNode(x);
  last.next = temp;
  temp.next = current;

  return;

}

最新文章

  1. Qt文件路径分隔符
  2. 你还记的那一年你我学习的--&gt;&gt;用表组织数据*(数据表)
  3. C# 多线程网络通信
  4. MYSQL注入天书之宽字节注入
  5. mysql 授权 打开全部
  6. bzoj1433:[ZJOI2009]假期的宿舍
  7. Storm-1.0.1+ZooKeeper-3.4.8+Netty-4.1.3 HA集群安装
  8. 基于 SSH 的工具叫 sshfs. sshfs 可以让你在本地直接挂载远程主机的文件系统
  9. input 等替换元素的baseline问题
  10. JS正则表达式分组模式
  11. 关于Windows 2019 antimalware 进程占用CPU 过多的处理方法 关闭windows 病毒防护的方法
  12. BZOJ2333 [SCOI2011]棘手的操作 堆 左偏树 可并堆
  13. HashMap怎样解决碰撞问题
  14. Matlab之视角旋转函数[转]
  15. HTML第三课——css盒子
  16. 利用Hibernate子查询(in) 得到部分字段(实体类的构造函数)
  17. pyCharm最新2019激活码
  18. javascript 知道这20个正则表达式,能让你少写1,000行代码
  19. mysql性能问题小解 Converting HEAP to MyIsam create_myisa
  20. ASP.NET错误处理的方式(一)

热门文章

  1. android .9图的作用
  2. 吐槽!important专用博文
  3. Yes, Virginia, Scala is hard
  4. linux 系统负载高 如何检查
  5. Python array,list,dataframe索引切片操作 2016年07月19日——智浪文档
  6. Python Day 01
  7. C++中常见错误整理(不定期更新)
  8. Win7下Hyenae的安装
  9. c++虚函数和内联构造函数
  10. 可滑动的ExpandableListView