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

58
Iterative_macros/tree.h Normal file
View File

@@ -0,0 +1,58 @@
/*
* =====================================================================================
*
* Filename: tree.h
*
* Description:
*
* Version: 1.0
* Created: 05/02/24 09:52:32 PM IST
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
#ifndef __TREE__
#define __TREE__
typedef struct tree_node {
struct tree_node *left;
struct tree_node *right;
struct tree_node *parent;
int data;
} tree_node_t;
typedef struct tree {
tree_node_t *root;
} tree_t;
int
add_tree_node_by_value(tree_t *tree, int n);
tree_t* init_tree(void);
tree_node_t* init_tree_node(int n);
/*Pre-requisites functions to write iterative
* macros for a tree.*/
tree_node_t *
get_left_most (tree_node_t *node);
tree_node_t *
get_next_inorder_succ (tree_node_t *node);
#define ITERATE_BST_BEGIN(treeptr, currentnodeptr) \
{ \
tree_node_t *_next = NULL; \
for(currentnodeptr = get_left_most(treeptr->root); currentnodeptr != NULL ; currentnodeptr = _next){ \
_next = get_next_inorder_succ(currentnodeptr);
#define ITERATE_BST_END }}
#endif