Comments (2)
如果swim()执行了,则pq数组和qp数组都变了,比如执行两次insert,insert(0,X),insert(1,A),在插入第二条信息的时候满足keys[0]>keys[1],交换数据,交换的是pq中记录的index,pq由原来的pq[1]=0,pq[2]=1变为pq[1]=1,pq[2]=0,由于qp是pq的逆序所以也要更新,由qp[0]=1,qp[1]=2变为qp[0]=2,qp[1]=1
https://github.com/xiaoyuzdy/Algorithms/blob/master/Algorithms/src/Number_2/IndexOfMinPQ_and_IndexOfMaxPQ.java
from algorithms.
谢谢!我知道了,在exch方法里会使qp跟随pq变化而变化,因为只有需要exch的时候pq里的值才会移动。而qp只要始终满足qp[pq[i]] = i, qp[pq[j]] = j就行了。谢谢!
from algorithms.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from algorithms.