Skip to content

MinHeap and MaxHeap realisations are broken #3158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Boiarshinov opened this issue Jun 21, 2022 · 6 comments
Closed

MinHeap and MaxHeap realisations are broken #3158

Boiarshinov opened this issue Jun 21, 2022 · 6 comments

Comments

@Boiarshinov
Copy link
Contributor

MinHeap and MaxHeap implementation are broken.
Instance of these heaps couldn't be instanciated with any not empty list of elements.

Here is a test code to reproduce:

@Test
void createFromList() {
    var elements = List.of(
            new HeapElement(5)
    );
    MaxHeap heap = new MaxHeap(elements);
    //similar with MinHeap
}

Stacktrace:

java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 1

	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
	at java.base/java.util.Objects.checkIndex(Objects.java:359)
	at java.base/java.util.ArrayList.get(ArrayList.java:427)
	at com.thealgorithms.datastructures.heaps.MaxHeap.getElementKey(MaxHeap.java:46)
	at com.thealgorithms.datastructures.heaps.MaxHeap.toggleUp(MaxHeap.java:59)
	at com.thealgorithms.datastructures.heaps.MaxHeap.insertElement(MaxHeap.java:97)
	at com.thealgorithms.datastructures.heaps.MaxHeap.<init>(MaxHeap.java:20)
@Boiarshinov
Copy link
Contributor Author

Boiarshinov commented Jun 21, 2022

This issue could be a good_first_issue for newcomers. I'm not pretend to solve it by myself 😄

@Jainam1401
Copy link
Contributor

@Boiarshinov Sir, I am new to the Open Source contribution, can you assign me the issue if no one is working on the issue?

@Jainam1401
Copy link
Contributor

@siriak Thanks for assigning me the issue. Can you please help me know this issue better and steps I need to follow to make contribution?

@siriak
Copy link
Member

siriak commented Jul 10, 2022

You need to make a fork of this repo, then make changes in it, and then make a pull request from your fork to this repo

@Jainam1401
Copy link
Contributor

@siriak Thanks for the help.

@Jainam1401
Copy link
Contributor

@siriak I have made the changes to the code but when I try to run it, I am facing some dependencies issue. Can you please help me out with it?

@siriak siriak closed this as completed Jul 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants