Question: Find attached the code to implement the following two functions: 1. Insert in Interval Heap 2. Display minimum and maximum values The interval heap is
Find attached the code to implement the following two functions: 1. Insert in Interval Heap 2. Display minimum and maximum values The interval heap is implemented as a one-dimensional array. The even indices store the minimum heap while odd indices store the max heap. please extend this code to add the function for deleting minimum and maximum values from the heap and please don't change anything this is working perfectly. please I request you provide the complete code along with the main functions of the complete program also add the the function for deleting minimum and maximum values from the heap.
#include
void insert_intervalheap(int a[], int *pos, int val) { int n=*pos, parent, parent1; (*pos)++; a[n] = val; if(n==0) return; if(n==1) { if(a[0]>a[1]) swap(a, 0, 1); return; } if (!(n%2)) { parent=get_parent(n); parent1=parent+1; if(a[n]a[parent1]) { swap(a,n , parent1); heapify_max(a, parent1); } } else { if(a[n] int get_max(int a[], int n) { if(n>1) return(a[1]); else return(a[0]); } void heapify_max(int a[], int n) { int parent=get_parent(n); while(n>1 && a[n] > a[parent]) { swap(a, n, parent); n = parent; parent=get_parent(n); } } void heapify_min(int a[], int n) { int parent=get_parent(n); while(n>0 && a[n] < a[parent]) { swap(a, n, parent); n = parent; parent=get_parent(n); } } main() { int i, interval_heap[100], n=0; while(1) { printf(" Enter any positive value to insert in interval heap and negative number to stop: "); scanf("%d", &i); if(i<0) break; insert_intervalheap(interval_heap, &n, i); printf(" Total elements in Interval Heap=%d Minimum=%d Maximum=%d",n, get_min(interval_heap,n), get_max(interval_heap,n)); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
