Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // documentation_module.c
- #include <stdio.h>
- #include <string.h>
- #include "documentation_module.h"
- int *check_available_documentation_module(int (*validate)(char*), int count, char **documents)
- {
- int *availability_mask = malloc(count * sizeof(int));
- for (int i = 0; i < count; i++) {
- char *document = documents[i];
- availability_mask[i] = validate(document);
- }
- return availability_mask;
- }
- // main_module_entry_point.c
- #include <stdio.h>
- #include <string.h>
- #include "print_module.h"
- #include "documentation_module.h"
- int validate(char* data)
- {
- int validation_result = (strcmp(data, Available_document) == 0);
- return validation_result;
- }
- int main()
- {
- print_log(print_char, Module_load_successb);
- int availability_mask_count = Documents_count;
- char **documents = Documents;
- int *availability_mask = check_available_documentation_module(validate, availability_mask_count, documents);
- // Output availability for each document
- for (int i = 0; i < availability_mask_count; i++) {
- char *document = documents[i];
- printf("%15s: %s\n", document, availability_mask[i] ? "available" : "unavailable");
- }
- free(availability_mask);
- return 0;
- }
- //////////////////////////////////////////////////////////////////
- #include <stdio.h>
- #include <stdlib.h>
- struct bstree_node {
- int value;
- struct bstree_node *left;
- struct bstree_node *right;
- };
- struct bstree_node *bstree_create_node(int value) {
- struct bstree_node *node = (struct bstree_node *)malloc(sizeof(struct bstree_node));
- node->value = value;
- node->left = NULL;
- node->right = NULL;
- return node;
- }
- void bstree_add_left(struct bstree_node *node, struct bstree_node *left) {
- node->left = left;
- }
- void bstree_add_right(struct bstree_node *node, struct bstree_node *right) {
- node->right = right;
- }
- void bstree_insert(struct bstree_node *root, struct bstree_node *node) {
- if (root->value > node->value) {
- if (root->left == NULL) {
- root->left = node;
- } else {
- bstree_insert(root->left, node);
- }
- } else {
- if (root->right == NULL) {
- root->right = node;
- } else {
- bstree_insert(root->right, node);
- }
- }
- }
- struct bstree_node *bstree_remove_node(struct bstree_node *root, int value) {
- if (root == NULL) {
- return NULL;
- }
- if (value < root->value) {
- root->left = bstree_remove_node(root->left, value);
- return root;
- } else if (value > root->value) {
- root->right = bstree_remove_node(root->right, value);
- return root;
- } else {
- if (root->left == NULL && root->right == NULL) {
- free(root);
- return NULL;
- } else if (root->left == NULL) {
- struct bstree_node *temp = root->right;
- free(root);
- return temp;
- } else if (root->right == NULL) {
- struct bstree_node *temp = root->left;
- free(root);
- return temp;
- } else {
- struct bstree_node *temp = root->right;
- while (temp->left != NULL) {
- temp = temp->left;
- }
- root->value = temp->value;
- root->right = bstree_remove_node(root->right, temp->value);
- return root;
- }
- }
- }
- void bstree_destroy(struct bstree_node *root) {
- if (root == NULL) {
- return;
- }
- bstree_destroy(root->left);
- bstree_destroy(root->right);
- free(root);
- }
- void bstree_apply_infix(struct bstree_node *root, void (*func)(int)) {
- if (root == NULL) {
- return;
- }
- bstree_apply_infix(root->left, func);
- func(root->value);
- bstree_apply_infix(root->right, func);
- }
- void bstree_apply_prefix(struct bstree_node *root, void (*func)(int)) {
- if (root == NULL) {
- return;
- }
- func(root->value);
- bstree_apply_prefix(root->left, func);
- bstree_apply_prefix(root->right, func);
- }
- void bstree_apply_postfix(struct bstree_node *root, void (*func)(int)) {
- if (root == NULL) {
- return;
- }
- bstree_apply_postfix(root->left, func);
- bstree_apply_postfix(root->right, func);
- func(root->value);
- }
- // bst_create_test.c
- #include <stdio.h>
- #include <stdlib.h>
- #include "bstree.h"
- int main(int argc, char *argv[]) {
- struct bstree_node *root = bstree_create_node(50);
- printf("Root node value: %d\n", root->value);
- bstree_destroy(root);
- return 0;
- }
- // bst_insert_test.c
- #include <stdio.h>
- #include <stdlib.h>
- #include "bstree.h"
- int main(int argc, char *argv[]) {
- struct bstree_node *root = bstree_create_node(50);
- bstree_insert(root, 25);
- bstree_insert(root, 75);
- bstree_insert(root, 12);
- bstree_insert(root, 37);
- bstree_insert(root, 62);
- bstree_insert(root, 87);
- printf("In-order traversal:\n");
- bstree_apply_infix(root, [](int value) {
- printf("%d\n", value);
- });
- bstree_destroy(root);
- return 0;
- }
- // bst_traverse_test.c
- #include <stdio.h>
- #include <stdlib.h>
- #include "bstree.h"
- int main(int argc, char *argv[]) {
- struct bstree_node *root = bstree_create_node(50);
- bstree_insert(root, 25);
- bstree_insert(root, 75);
- bstree_insert(root, 12);
- bstree_insert(root, 37);
- bstree_insert(root, 62);
- bstree_insert(root, 87);
- printf("In-order traversal:\n");
- bstree_apply_infix(root, [](int value) {
- printf("%d\n", value);
- });
- printf("Pre-order traversal:\n");
- bstree_apply_prefix(root, [](int value) {
- printf("%d\n", value);
- });
- printf("Post-order traversal:\n");
- bstree_apply_postfix(root, [](int value) {
- printf("%d\n", value);
- });
- bstree_destroy(root);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement