java数据结构与算法之改良顺序表与双链表类似ArrayList和LinkedList(带Iterator迭代器与fast-fail机制)
shinezejian / javastructures Goto Github PK
View Code? Open in Web Editor NEWLinkedList Design By java
LinkedList Design By java
我在calculatePostfixValue类中看到的一段
查看来自后端架构师技术图谱 的 栈
//postifx = "1392-*+9+";
char ch=postfix.charAt(i);
if (ch>='0' && ch<='9')
{
result=0;
while (ch!=' ')
{
//将整数字符转为整数值ch=90
result = result*10 + Integer.parseInt(ch+"");
i++;
ch = postfix.charAt(i);
}
i++;
stack.push(result);//操作数入栈
}
这里的Integer.parseInt(ch+"");
不会报错?
这里while 里面的ch = postfix.charAt(i);
,不是会读取到操作符吗
result*10
这个也没明白
测试代码:
public static void main(String[] args) {
AVLTree<Integer> t = new AVLTree<>();
t.insert(70);
t.insert(40);
t.insert(10);
t.insert(100);
t.insert(120);
t.insert(130);
t.insert(140);
t.insert(150);
t.insert(160);
t.insert(135);
t.insert(170);
t.insert(145);
t.remove(160);
}
可见节点170
这棵子树是不平衡的
//原本
public HeadSingleILinkedList(Node head) {
this();
this.headNode.next =rear.next= head;
rear=rear.next;//更新末尾指针指向
}
//我觉得应该是 this() 初始化后的 rear ben就是null 所以 rear = head 就行了吧
public HeadSingleLinkedList(Node head){
this();
this.headNode.next = rear = head;
rear = rear.next;
}
//原来代码 存在问题 如果有多个data 包括头节点时
@OverRide
public boolean removeAll(T data) {
boolean isRemove=false;
if(this.head!=null&&data!=null){
//如果移除的是头结点
if(data.equals(this.head.data)){
this.head=this.head.next;
isRemove=true;
}else {
Node<T> front=this.head;
Node<T> pre=front.next;
//查找所有数据相同的结点并删除
while (pre!=null){
if(data.equals(pre.data)){
//更改指针指向
front.next=pre.next;
pre =front.next;
isRemove=true;
}else {
front=pre;
pre=pre.next;
}
}
}
}else {//data=null || this.head=null
isRemove=false;
}
return isRemove;
}
//修改后代码
@OverRide
public boolean removeAll(T data) {
boolean isRemove = false;
if(this.head != null && data != null){
//如果移除的是头节点
if(data.equals(this.head.data)){
this.head = this.head.next;
isRemove = true;
}
Node<T> front = this.head;
Node<T> pre = front.next;
//查找所有数据相同的节点并删除
while(pre != null){
if(data.equals(pre.data)){
front.next = pre.next;
pre = front.next;
isRemove = true;
}else {
front = pre;
pre = pre.next;
}
}
}
return isRemove;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.