Make a habit to use Iterative Macro for iterating Data Structure

This commit is contained in:
2024-02-05 22:46:31 +05:30
parent 19e67acd4c
commit df3c77faea
10 changed files with 3178 additions and 0 deletions

68
Iterative_macros/dll.h Normal file
View File

@@ -0,0 +1,68 @@
/*
* =====================================================================================
*
* Filename: dll.h
*
* Description:
*
* Version: 1.0
* Created: 05/02/24 08:03:38 PM IST
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
/*Header file for Doubly Linked List*/
typedef struct dll_node_{
void *data;
struct dll_node_ *left;
struct dll_node_ *right;
} dll_node_t;
typedef struct dll_{
dll_node_t *head;
int (*key_match)(void *, void *);
int (*comparison_fn)(void *, void *);
} dll_t;
void
register_key_match_callback(dll_t *dll, int (*key_match)(void *, void *));
void
register_comparison_callback(dll_t *dll, int (*comparison_cb)(void *, void *));
/*Generic Search function*/
void *
dll_search_by_key (dll_t *dll, void *key);
int
dll_priority_insert_data (dll_t *dll, void *data);
/* Public Function declaration to create and return
* a new empty doubly linked list*/
dll_t *
get_new_dll();
/* Public Function declaration to add the appication
* data to DLL*/
int
add_data_to_dll(dll_t *dll, void *appn_data);
/*Macro to iterate over a DLL*/
#define ITERATE_LIST_BEGIN(list_ptr, node_ptr) \
{ \
dll_node_t *_node_ptr = NULL; \
node_ptr = list_ptr->head; \
for(; node_ptr!= NULL; node_ptr = _node_ptr){ \
if(!node_ptr) break; \
_node_ptr = node_ptr->right;
#define ITERATE_LIST_END }}