Modify your min-heap that stores arbitrary structs Using C language Create 2 files: min_heap.c and min_heap.h To
Fantastic news! We've Found the answer you've been seeking!
Question:
Modify your min-heap that stores arbitrary structs Using C language
Create 2 files: min_heap.c and min_heap.h
Transcribed Image Text:
To create a min-heap that can sort *any datatype*, we'll utilize void* and function pointers. Heap* CreateHeap(void** data, int num_elems, int (*Compare)(void*, void*)) returns an empty heap H that is set up to store at most n elements. This operation takes O(N) time, as it involves initializing the array that will hold the heap. void Insert(Heap* heap, int val) inserts the int val into heap heap. If the heap currently has n elements, this takes O(log n) time. void* ExtractMin(Heap* heap) identifies and deletes an element with minimum value from a heap. void* Delete(Heap* heap, int position) deletes the element in heap position i. This is implemented in O(log n) time for heaps that have n elements. void BubbleUp(Heap* heap, int index) bubbles the element at location index up to its correct position. void BubbleDown (Heap* heap, int index) bubbles the element at location index down to its correct position. void Swap (Heap* heap, int first_ind, int second_ind) swaps the elements located at first_ind and second_ind in the heap. DestroyHeap (Heap* heap) frees all resources associated with heap heap. ● ● ● ● ● ● ● To create a min-heap that can sort *any datatype*, we'll utilize void* and function pointers. Heap* CreateHeap(void** data, int num_elems, int (*Compare)(void*, void*)) returns an empty heap H that is set up to store at most n elements. This operation takes O(N) time, as it involves initializing the array that will hold the heap. void Insert(Heap* heap, int val) inserts the int val into heap heap. If the heap currently has n elements, this takes O(log n) time. void* ExtractMin(Heap* heap) identifies and deletes an element with minimum value from a heap. void* Delete(Heap* heap, int position) deletes the element in heap position i. This is implemented in O(log n) time for heaps that have n elements. void BubbleUp(Heap* heap, int index) bubbles the element at location index up to its correct position. void BubbleDown (Heap* heap, int index) bubbles the element at location index down to its correct position. void Swap (Heap* heap, int first_ind, int second_ind) swaps the elements located at first_ind and second_ind in the heap. DestroyHeap (Heap* heap) frees all resources associated with heap heap. ● ● ● ● ● ● ●
Expert Answer:
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these algorithms questions
-
answer the question clearly You are building a flight-control system for which a convincing safety case must be made. Would you assign the tasks of safety requirements engineering, test case...
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
2. Imagine a college basketball team has the following supply and demand figures for a typical game: Price 8 16 24 32 40 Quantity Demanded 28000 22000 16000 10000 4000 Quantity Supplied 16000 16000...
-
Using the income statement for Sentinel Travel Service shown in Practice Exercise 1-4B, prepare a statement of owner's equity for the year ended August 31, 2019. Barb Schroeder, the owner, invested...
-
Find the saddle point for the game having the following payoff table. Use the minimax criterion to find the best strategy for each player. Does this game have a saddle point? Is it a stable game?...
-
Let \(R\) and \(\widetilde{R}\) be two independent \(\mathrm{BES}^{3}\) processes. The process \(Y_{t}=R_{t}^{-1}-\left(\widetilde{R}_{t} ight)^{-1}\) is a local martingale with null expectation....
-
Wal-Mart Stores, Inc. (Walmart) is the largest retailing firm in the world. Building on a base of discount stores, Walmart has expanded into warehouse clubs and Supercenters, which sell traditional...
-
ABC corporation is manufacturing one product and uses standard cost system to evaluate performance. The manager who is responsible of buying the needed quantity of raw materials was able to buy a...
-
1.Identify the three countries with the most favorable collection experience as measured by their receivables turnover ratios. RTR US = RTR Saudi Arabia = RTR UK = 2. Which country appears to have...
-
If an elastic ball is dropped from a height of 4.5 meters and bounces 25 of the distance it drops each time then the total vertical distance in meters traveled by the ball is closest to:
-
How to perform the preparation technique for recipe of Marinated kangaroo fillet?
-
Can you elucidate the integration of advanced remote sensing technologies and real-time data analytics in facilitating situational awareness and enhancing the efficiency of recovery operations in...
-
What is the net cash increase ALL-STAR AUTOMOTIVE COMPANY Statement of Cash Flows For the Year Ended December 31, Year 2 Cash flows from operating activities: Cash receipts from revenue $25,000 Cash...
-
To make sure immunisations records are up-to-date, education and care services must obtain a copy of the child's immunisation record during enrolment and request a new copy each year. List four (4)...
-
In this experiment, electrons are "boiled" off of a hot piece of metal (filament). They are then accelerated up to speed using a potential difference AV. After they are accelerated, they enter a...
-
What is heterocyclic base?
-
Shreemaya Hotel in !adore was facing a problem of low demand for its rooms due to off season. The Managing Director (MD) of the hotel, Mrs. Sakina was very worried. She called upon the Marketing...
-
Show how to implement a queue using two stacks. Analyze the running time of the queue operations.
-
Given a set Q of points in the plane, we define the convex layers of Q inductively. The first convex layer of Q consists of those points in Q that are vertices of CH (Q). For i > 1, define Q i to...
-
Prove that the determinant of a lower-triangular or upper-triangular matrix is equal to the product of its diagonal elements. Prove that the inverse of a lower-triangular matrix, if it exists, is...
-
You are provided with the cost of goods manufactured statement and income statement for Prider Manufacturers Ltd. Required (a) Prepare the closing entries for Prider Manufacturers Ltd. Direct...
-
Basic Chemicals Ltd produces a highly flammable chemical product. The company experienced a flood on 1 April 2019 that destroyed its entire work in process inventory but did not affect the raw...
-
The unadjusted trial balance of Innovative Computers Pty Ltd on 30 June 2019 is presented below. The following additional information is available. 1. The inventories as of 30 June 2019 were as...
Mathematica Navigator Mathematics Statistics And Graphics 3rd Edition - ISBN: 0123741645 - Free Book
Study smarter with the SolutionInn App