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