C Everything
This is a C repository containing a curated set of generic data structures and algorithm.
heap.c File Reference

Contains definitions of routines supported by heap. More...

#include "heap.h"

Go to the source code of this file.

Functions

void heap_insert (t_gen d, t_gen data)
 
Insert an element to heap More...
 
t_gen heap_extract_root (t_gen d)
 
Extract the root from heap More...
 
void heap_build (t_gen d)
 
Build a heap given a array More...
 
void heap_sort (t_gen d)
 
Heap sort the data More...
 
int heap_len (t_gen h)
 
heap count More...
 
void heap_print (t_gen d)
 
heap_print_info More...
 
bool heap_empty (t_gen d)
 
To check if heap empty More...
 
bool heap_full (t_gen d)
 
To check if heap full More...
 
t_gen heap_update_key (t_gen d, t_gen val, int idx)
 
heap update value of given node More...
 
void destroy_heap (t_gen d)
 
Destroy the instance of the heap More...
 
t_gen create_heap (char *name, t_gen data, int size, e_heaptype htype, t_dparams *prm)
 
Create an instance of heap More...
 
void heapify_up (t_heap *h, int idx)
 
Preserve heap property on insert by heapifying from bottom to root More...
 
void heapify (t_heap *h, int idx)
 
Rearrange a heap to maintain the heap property aka heapyfy_down More...
 
char * get_heaptype_name (e_heaptype type)
 

Detailed Description

Contains definitions of routines supported by heap.

Definition in file heap.c.

Function Documentation

◆ create_heap()

t_gen create_heap ( char *  name,
t_gen  data,
int  size,
e_heaptype  htype,
t_dparams prm 
)


Create an instance of heap

Parameters
name- Name of heap instance
size- Max size of heap instance
type- Type of heap to be created
data- Array pointer to build heap
prm- Data type specific parameters
Returns
- Pointer to instance of heap

Definition at line 29 of file heap.c.

◆ destroy_heap()

void destroy_heap ( t_gen  d)


Destroy the instance of the heap

Parameters
d- Pointer to instance of heap
Returns
- NA

Definition at line 294 of file heap.c.

◆ get_heaptype_name()

char* get_heaptype_name ( e_heaptype  type)

Definition at line 306 of file heap.c.

◆ heap_build()

void heap_build ( t_gen  d)


Build a heap given a array

Parameters
d- Pointer to instance of heap
Returns
- NA

Definition at line 177 of file heap.c.

◆ heap_empty()

bool heap_empty ( t_gen  d)


To check if heap empty

Parameters
d- Pointer to instance of heap
Returns
- true if heap empty

Definition at line 81 of file heap.c.

◆ heap_extract_root()

t_gen heap_extract_root ( t_gen  d)


Extract the root from heap

Parameters
d- Pointer to instance of heap
Returns
- Pointer to extracted root node element of heap

Definition at line 194 of file heap.c.

◆ heap_full()

bool heap_full ( t_gen  d)


To check if heap full

Parameters
d- Pointer to instance of heap
Returns
- true if heap full

Definition at line 69 of file heap.c.

◆ heap_insert()

void heap_insert ( t_gen  d,
t_gen  data 
)


Insert an element to heap

Parameters
d- Pointer to instance of heap
data- Pointer to data that has to be added to heap
Returns
- NA

Definition at line 120 of file heap.c.

◆ heap_len()

int heap_len ( t_gen  h)


heap count

Parameters
d- Pointer to instance of heap
Returns
- heap length

Definition at line 284 of file heap.c.

◆ heap_print()

void heap_print ( t_gen  d)


heap_print_info

Parameters
d- Pointer to instance of heap
Returns
- NA

Definition at line 322 of file heap.c.

◆ heap_sort()

void heap_sort ( t_gen  d)


Heap sort the data

Parameters
d- Pointer to instance of heap
Returns
- NA

Definition at line 223 of file heap.c.

◆ heap_update_key()

t_gen heap_update_key ( t_gen  d,
t_gen  val,
int  idx 
)


heap update value of given node

Parameters
d- Pointer to instance of heap
val- Pointer of value to be copied to given heap node
idx- Node idx of heap to which value has to be updated idx b/w 0 and heap node count -1
Returns
- Pointer to updated node data

Definition at line 250 of file heap.c.

◆ heapify()

void heapify ( t_heap h,
int  idx 
)


Rearrange a heap to maintain the heap property aka heapyfy_down

Parameters
d- Pointer to instance of heap
idx- Index of node to heapify
Returns
- NA

Definition at line 141 of file heap.c.

◆ heapify_up()

void heapify_up ( t_heap h,
int  idx 
)


Preserve heap property on insert by heapifying from bottom to root

Parameters
d- Pointer to instance of heap
idx- Index of node to heapify
Returns
- NA

Definition at line 95 of file heap.c.