Giter Club home page Giter Club logo

Comments (2)

xiaoyuzdy avatar xiaoyuzdy commented on July 21, 2024

如果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.

LiBo430 avatar LiBo430 commented on July 21, 2024

谢谢!我知道了,在exch方法里会使qp跟随pq变化而变化,因为只有需要exch的时候pq里的值才会移动。而qp只要始终满足qp[pq[i]] = i, qp[pq[j]] = j就行了。谢谢!

from algorithms.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.