输出倒数第K个节点
public Node back(int k){//输出倒数第K个节点
Node slow = this.head;
Node fast = this.head;
if (k<1||k>size){
System.out.println("请输入正确的K");
return null;
}
for (;k>0;k--){
fast=fast.next;
}
for (;fast != null;){
fast=fast.next;
slow=slow.next;
}
return slow;
}
小于x的放前面,其余的放后面。
public void sort(int x){//排序:小于x的放前面,其余的放后面
if (head ==null){
return;
}
Node af = null;
Node ae = null;
Node bf = null;
Node be = null;
Node cur = this.head;
for (;cur !=null;cur=cur.next){
if (cur.val < x){
if (af == null){
af = cur ;
ae = cur ;
}else {
ae.next = cur;
ae = cur;
}
}else {
if (bf == null){
bf = cur ;
be = cur ;
}else {
be.next = cur;
be = cur;
}
}
}
be.next=null;
if (af == null){
this.head = bf;
return;
}
if (bf == null){
ae.next = null;
this.head = af;
return;
}
ae.next=bf;
return;
}
回文结构:12321、123321、181等
public boolean plalindrome(){
Node prev =midNode();
Node cur = prev.next;
Node curNext = cur.next;
for (;curNext!=null;){
cur.next = prev;
prev = cur;
cur = curNext;
curNext = curNext.next;
}
cur.next = prev;
prev = this.head;
for (;prev != cur && prev.next != cur ;){
if (cur.val != prev.val){
return false;
}
prev=prev.next;
cur = cur.next;
}
if (cur.val != prev.val){
return false;
}
return true;
}
public boolean ring(){
Node fast = this.head;
Node slow = this.head;
for (;fast!=null && fast.next!=null;){
fast=fast.next.next;
slow=slow.next;
if (slow == fast){
break;
}
}
if (fast == null || fast.next==null){
return false;
}
return true;
}
判断有环并 输出环的入口节点
public int ringB(){
Node fast = this.head;
Node slow = this.head;
for (;fast!=null && fast.next!=null;){
fast=fast.next.next;
slow=slow.next;
if (slow == fast){
break;
}
}
if (fast == null || fast.next==null){
return -1;
}
fast = this.head;
for (;fast != slow;){
fast = fast.next;
slow = slow.next;
}
return slow.val;
}
有序链表清除重复内容,且不保留重复内容
public void clear() {
Node cur = this.head;
for (;cur.next!=null;){
if (cur.val == cur.next.val){
del(cur.val);
}
cur=cur.next;
}
}
一、MVC MVC模式的意思是,软件可以分成三个部分。 视图(View):用户界面。 控...
我们知道微软将会在今年给Windows10更换全新设计的UI,让Windows10的界面更加整...
一、简介 本设计为硬币图像识别统计装置通过数码相机获取平铺无重叠堆积的硬币的...
git工作区,暂存区,版本库之间的关系: 我们建立的项目文件夹就是工作区,在初...
今日国内领先的智能数据服务运营商觉非科技完成近亿元A轮融资。本轮融资由和高资...
前言 关于Window,你了解多少呢?看看下面这些问题你都能答上来吗。 如果你遇到这...
本文实例讲述了jsp中page指令用法。分享给大家供大家参考。具体如下: 一、JSP ...
首先给扑克牌中每张牌设定一个编号,下面算法实现的编号规则如下: u 红桃按照从...
大家好,今天我们来简单的聊一聊缓存问题。什么是缓存呢?它在系统设计中是在一个...
从功能测试、性能测试、界面测试、安全性测试、易用性、兼容性测试、震动测试七...