Fix for issue #254 : Heap-sort implemented using java #258
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
✨ Pull Request
📓 Referenced Issue
Fixes: #254
ℹ️ About the PR
This PR addresses the implementation of Heap Sort using Java. The code takes input from the user, builds a max heap, and sorts the array in ascending order. The implementation also ensures that the array is printed after sorting for verification. The solution handles large inputs using
long
instead ofint
to avoid overflow errors during execution.Specifically:
Implemented Heap sort
To reiterate how the code works:
Heapify function: Ensures that the tree rooted at a given index i satisfies the max-heap property.
Sort function: First builds a max-heap and then extracts the largest element (root of the heap) to put it at the end of the array.
It then reduces the size of the heap and heapifies the remaining elements.
Main function: Takes user input for the number of elements and the elements themselves, sorts the array using the HeapSort object, and prints the sorted array.
🖼️ Testing Scenarios / Screenshots
Tested on:
online java compiler using an online IDE
Screenshots: