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]