From eb58ca21a4e8fce9e166acb5cf9efc9fc5d62086 Mon Sep 17 00:00:00 2001 From: Raja Muhammad Bilal Arshad Date: Sat, 19 Oct 2024 22:19:40 +0500 Subject: [PATCH] Update heapsort.c A bit more Efficient and convenient... --- heapsort.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/heapsort.c b/heapsort.c index 3d1d0f4d..86a8dfbb 100644 --- a/heapsort.c +++ b/heapsort.c @@ -4,8 +4,13 @@ void main() { int heap[10], no, i, j, c, root, temp; - printf("\n Enter no of elements :"); - scanf("%d", &no); +printf("\nEnter number of elements (max 10): "); +scanf("%d", &no); +if (no > 10) +{ + printf("Number of elements exceeds the maximum limit of 10.\n"); + return 1; // Exit if the number of elements exceeds the limit +} printf("\n Enter the nos : "); for (i = 0; i < no; i++) scanf("%d", &heap[i]); @@ -37,9 +42,17 @@ void main() do { c = 2 * root + 1; /* left node of root element */ - if ((heap[c] < heap[c + 1]) && c < j-1) - c++; - if (heap[root]