Giter Site home page Giter Site logo

Add Max Heap? about javascript-algorithms HOT 6 CLOSED

trekhleb avatar trekhleb commented on April 28, 2024
Add Max Heap?

from javascript-algorithms.

Comments (6)

trekhleb avatar trekhleb commented on April 28, 2024

@bresson yes, please, just feel free add MaxHeap if you want.

I think it should be added in the same folder as MinHeap. We would need to have an AbstractHeap.js class that will be a base class for the MinHeap.js and MaxHep.js just to avoid code duplication. What do you think?

from javascript-algorithms.

bresson avatar bresson commented on April 28, 2024

@trekhleb Sounds great! I'll work on a AbstractHeap and MaxHeap first and get a PR, then circle back to refactor MinHeap to inherit from the AbstractHeap.

Quick clarification, Java has dedicated Abstract classes so in JS we're thinking along the lines of following Java's abstract template - a base class which cannot be instantiated and will have abstract and non-abstract methods?

from javascript-algorithms.

trekhleb avatar trekhleb commented on April 28, 2024

@bresson yeah, unfortunately we will need to imitate abstractness. I was thinking about something like this:

class Heap {
  constructor() {
    if (new.target === Heap) {
      throw new TypeError('Cannot construct Heap instance directly');
    }
  }

   // Methods that are common for both Min and Max heaps.
}

class MinHeap extends Heap {
  constructor() {
    super();
  }

  // MinHeap specific methods here.
}

Something like that. Just to avoid code duplication. Maybe it is even not abstractness but rather a parent class that just may not be instantiated.

from javascript-algorithms.

bresson avatar bresson commented on April 28, 2024

Sounds great - aiming for PR in about a week unless work interferes.

from javascript-algorithms.

kersov avatar kersov commented on April 28, 2024

Hi @bresson, I started to implement MaxHeap before this issue is created.
I have prepared PR #167
but I will change it according to the @trekhleb comment above.

from javascript-algorithms.

trekhleb avatar trekhleb commented on April 28, 2024

Thanks for PR @okersov

from javascript-algorithms.

Related Issues (20)

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.