Skip to content
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

Fix for issue #254 : Heap-sort implemented using java #258

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

udayjordan
Copy link

✨ 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 of int 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:

Screenshot 2024-10-16 164257
Screenshot 2024-10-16 164510

@udayjordan
Copy link
Author

I would like you to merge my file since the conflict was raised regarding heap sort the code which was pulled in your file does not take input from the user and also there is a range problem with the code for large numbers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Heap Sort
1 participant