Algorithms_in_C  1.0.0
Set of algorithms implemented in C.
dict.h
1 /*
2  author: Christian Bender
3  public interface for the dictionary.
4 
5  The dictionary prepares space for 1000 elements.
6 */
7 
8 #ifndef __DICT__H
9 #define __DICT__H
10 
11 #define MAXELEMENTS 1000
12 
13 /*
14  special data type called 'Dictionary'
15  for generic use
16 */
17 typedef struct Dict
18 {
19  /*
20  void* array for generic use of the dictionary.
21  there actual saves the entries.
22  */
23  void *elements[MAXELEMENTS];
24 
25  /* contains the number of elements in this dictionary */
26  int number_of_elements;
27 
28 } Dictionary;
29 
30 /*
31  create_dict: is a simple constructor for creating
32  a dictionary and setting up the
33  member field 'number_of_elements'
34  and prepares the inner array 'elements'
35 */
36 Dictionary *create_dict(void);
37 
38 /*
39  add_item_label: adds item (void*) to the dictionary at given label
40  returns 0 if adding was sucessful otherwise -1
41 */
42 int add_item_label(Dictionary *, char label[], void *);
43 
44 /*
45  add_item_index: adds item (void*) to the dictionary at given index (int)
46  returns 0 if adding was sucessful otherwise -1
47 */
48 int add_item_index(Dictionary *, int index, void *);
49 
50 /*
51  get_element: returns the element at given label
52 */
53 void *get_element_label(Dictionary *, char[]);
54 
55 /*
56  get_element: returns the element at given index
57 */
58 void *get_element_index(Dictionary *, int);
59 
60 /*
61  simple destrcutor function
62 */
63 void destroy(Dictionary *);
64 
65 #endif
delete_bt
void delete_bt(node **root, int ele)
deletion of a node from the tree if the node isn't present in the tree, it takes no action.
Definition: threaded_binary_trees.c:173
main
int main()
Main funcion.
Definition: binary_search_tree.c:249
minimum
void minimum(const void *a, const void *b, void *c)
Utility for test A function compare for minimum between two integers This function is used as combine...
Definition: segment_tree.c:194
data
Definition: prime_factoriziation.c:25
node
Node, the basic data structure in the tree.
Definition: binary_search_tree.c:15
inOrder
void inOrder(node *root)
Traversal procedure to list the current keys in the tree in order of value (from the left to the righ...
Definition: binary_search_tree.c:238
AVLnode
Definition: avl.c:5
segment_tree_update
void segment_tree_update(segment_tree *tree, size_t index, void *val)
For point updates This function updates the element at given index and also updates segment tree acco...
Definition: segment_tree.c:79
node::data
int data
data of the node
Definition: binary_search_tree.c:18
newNode
node * newNode(int data)
The node constructor, which receives the key value input and returns a node pointer.
Definition: binary_search_tree.c:28
Node::data
int data
stores the number
Definition: threaded_binary_trees.c:28
Node::rlink
struct Node * rlink
link to right child
Definition: threaded_binary_trees.c:30
Node
Node, the basic data structure of the tree.
Definition: threaded_binary_trees.c:27
Dict
Definition: dict.h:18
combine_function
void(* combine_function)(const void *a, const void *b, void *result)
Function that combines two data to generate a new one The name of function might be misleading actual...
Definition: segment_tree.c:33
main
int main()
Driver code.
Definition: client.c:70
segment_tree::root
void * root
the root of formed segment tree
Definition: segment_tree.c:40
main
int main()
Main Function.
Definition: segment_tree.c:231
segment_tree::identity
void * identity
identity element for combine function
Definition: segment_tree.c:41
segment_tree::combine
combine_function combine
the function to be used to combine two node's data to form parent's data
Definition: segment_tree.c:47
postorder_display
void postorder_display(node *curr)
performs postorder traversal param[in] curr node pointer to the topmost node of the tree
Definition: threaded_binary_trees.c:143
node
struct Node node
Node, the basic data structure of the tree.
search
void search(node *root, int ele)
searches for the element
Definition: threaded_binary_trees.c:98
find
int find(node *root, int data)
Search procedure, which looks for the input key in the tree and returns 1 if it's present or 0 if it'...
Definition: binary_search_tree.c:152
test
static void test()
Test RMQ Testing Segment tree using Range Minimum Queries.
Definition: segment_tree.c:205
getMax
node * getMax(node *root)
Utilitary procedure to find the greatest key in the left subtree.
Definition: binary_search_tree.c:72
Node::llink
struct Node * llink
link to left child
Definition: threaded_binary_trees.c:29
preorder_display
void preorder_display(node *curr)
performs preorder traversal param[in] curr node pointer to the topmost node of the tree
Definition: threaded_binary_trees.c:157
max
#define max(a, b)
shorthand for maximum value
Definition: kohonen_som_topology.c:39
segment_tree_init
segment_tree * segment_tree_init(void *arr, size_t elem_size, size_t len, void *identity, combine_function func)
Initializes Segment Tree Accquires memory for segment tree and fill the leaves of segment tree with d...
Definition: segment_tree.c:140
CArray
Definition: carray.h:32
node::left
struct node * left
left child
Definition: binary_search_tree.c:16
inorder_display
void inorder_display(node *curr)
performs inorder traversal param[in] curr node pointer to the topmost node of the tree
Definition: threaded_binary_trees.c:129
segment_tree_dispose
void segment_tree_dispose(segment_tree *tree)
Dispose Segment Tree Frees all heap memory accquired by segment tree.
Definition: segment_tree.c:162
func
void func(int sockfd)
Continuous loop to send and receive over the socket.
Definition: client.c:37
segment_tree_build
void segment_tree_build(segment_tree *tree)
Builds a Segment tree It is assumed that leaves of tree already contains data.
Definition: segment_tree.c:55
node
struct node node
Node, the basic data structure in the tree.
insert
node * insert(node *root, int data)
Insertion procedure, which inserts the input key in a new node in the tree.
Definition: binary_search_tree.c:46
create_node
node * create_node(int data)
creates a new node param[in] data value to be inserted
Definition: threaded_binary_trees.c:38
segment_tree_query
void segment_tree_query(segment_tree *tree, long long l, long long r, void *res)
Query the segment tree This function helps in range query of segment tree This function assumes that ...
Definition: segment_tree.c:105
segment_tree_print_int
void segment_tree_print_int(segment_tree *tree)
Prints the data in segment tree The data should be of int type A utility to print segment tree with d...
Definition: segment_tree.c:175
insert_bt
void insert_bt(node **root, int data)
inserts a node into the tree param[in,out] root pointer to node pointer to the topmost node of the tr...
Definition: threaded_binary_trees.c:51
segment_tree::elem_size
size_t elem_size
size in bytes of each data element
Definition: segment_tree.c:42
segment_tree::length
size_t length
total size of array which segment tree represents
Definition: segment_tree.c:43
segment_tree
This structures holds all the data that is required by a segment tree.
Definition: segment_tree.c:39
height
int height(node *root)
Utilitary procedure to measure the height of the binary tree.
Definition: binary_search_tree.c:187
node::right
struct node * right
right child
Definition: binary_search_tree.c:17
purge
void purge(node *root)
Utilitary procedure to free all nodes in a tree.
Definition: binary_search_tree.c:217
segment_tree
struct segment_tree segment_tree
This structures holds all the data that is required by a segment tree.
main
int main()
main function
Definition: threaded_binary_trees.c:255