Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.
// declaration of a binary tree with pointers to left and right children// #include <assert.h>#include <stdio.h>#include <stdlib.h> #define SIZE 9 typedef int DATA; struct node{ DATA dat; struct node *left; struct node *right;}; typedef struct node bNODE;typedef node *BTREE; void inorder(const BTREE root);void preorder(const BTREE root);void postorder(const BTREE root);BTREE makeTree(int a[], int i, int SIZE);BTREE new_node();BTREE init_node(DATA dat1, BTREE par1, BTREE par2);BTREE insert(BTREE parent, BTREE root, int item);int count_nodes(BTREE root, int cnt);int count_Lnodes(BTREE root, int cnt); int *makeArray(BTREE root, int val[]);int *inorder_traversal(int i, BTREE b_tree, int *valPtr);int *order_array(int a[]);void divide_array(int a[], int b[], int c[], int SIZE);int find_center(int a[], int SIZE); int main(){// int command; BTREE b_tree; int array_of_ints[] = {5, 10, 2, 5, 7, 12, 3, 9, 8}; int val[9] = {0}; int *valPtr = 0; b_tree = makeTree)array_of_ints, 0, SIZE); printf("Tree printed 'in-order'\n"); preorder (b_tree); putchar('\n'); printf("Number of nodes = %d\n", count_nodes(b_tree, 0)); printf("Number of Leaf nodes = %d\n", count_Lnodes(b_tree, 0)); printf("Here is the array made from the tree:\n"); valPtr = makeArray(b_tree, val); return 0; } // put an array in alphabetical orderint *order_array(int a[]){ int j, i, temp; int *b = a; for (i = 0; i < SIZE-1; ++i) for (j = i+1; j < SIZE; ++j) if (a[i] > a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; }return b;} // put an array in alphabetical orderint *order_array(int a[]){ int j, i, temp; int *b = a; for (i = 0; i < SIZE-1; ++i) for (j = i+1; j < SIZE; ++j) if (a[i] > a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; } return b;} // send function a, the array to be divided, and b and c, the 2 array pointersvoid divide_array(int a[], int b[], int c[], int SIZE){ int i, j; for (i = 0; i < SIZE/2; ++i) b[i] = a[i]; i++; // removing middle item, the one being added for (j = 0; i < SIZE; ++i, ++j) c[j] = a[i];} // find center of an arrayint find_center(int a[], int SIZE){ int i = 0, center; while (i < SIZE) ++i; center = i / 2; printf("%d.. %d .. %d\n", i, center, a[center]); return a[center];} // create ordered binary tree using recursion, divide array, then insert center intBTREE makeTree(int a[], int i, int SIZE){ int b[SIZE] = {0}, c[SIZE] = {0}; if(SIZE == 0) return NULL; if(SIZE == 1) init_node(a[0], NULL, NULL); if(i <= SIZE) { divide_array(a, b, c, SIZE); return init_node(find_center(a, SIZE), makeTree(b, 2 * i + 1, SIZE / 2), makeTree(c, 2 * i + 2, SIZE - SIZE / 2 - 1)); }} // create array using inorder binary tree traversal and printint *makeArray(BTREE root, int val[]){ int i = 0, *valPtr; valPtr = val; valPtr = inorder_traversal(i, root, val); putchar('\n'); return valPtr;} // create array from binary treeint *inorder_traversal(int i, BTREE parent, int val[]){ int *valPtr; valPtr = val; if (parent != NULL) { inorder_traversal(i, parent->left, val); val[i] = parent->dat; printf("%d ", val[i]); ++i; inorder_traversal(i, parent->right, val); } return valPtr;} // inorder binary tree traversal and printvoid inorder(const BTREE parent){ if (parent != NULL) { inorder(parent->left); printf("%d ", parent->dat); inorder(parent->right); }} // preorder binary tree traversal and printvoid preorder(const BTREE root){ if (root != NULL) { printf("%d ", root->dat); preorder(root->left); preorder(root->right); }} // creating binary treesBTREE new_node(){ return (malloc(sizeof(bNODE)));} BTREE init_node(dat1, BTREE par1, BTREE par2){ BTREE t; t = new_node(); t->dat = dat1; t->left = par1; t->right = par2; return t;} // count total number of nodesint count_nodes(BTREE root, int cnt){ if (root != NULL) { cnt = count_nodes(root->left, cnt); /* recur left */ cnt = count_nodes(root->right, ++cnt); /* recur right */ } return cnt;} // count number of leaf nodesint count_Lnodes(BTREE root, int cnt){ if (root != NULL) { cnt = count_Lnodes(root->left, cnt); cnt = count_Lnodes(root->right, cnt); if (root->left == NULL && root->right == NULL) ++cnt; } return cnt;}// declaration of a binary tree with pointers to left and right children//
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#define SIZE 9
typedef int DATA;
struct node
{
DATA dat;
struct node *left;
struct node *right;
};
typedef struct node bNODE;
typedef node *BTREE;
int siz=9;
void inorder(const BTREE root);
void preorder(const BTREE root);
void postorder(const BTREE root);
BTREE makeTree(int a[], int i, int siz);
BTREE new_node();
BTREE init_node(DATA dat1, BTREE par1, BTREE par2);
BTREE insert(BTREE parent, BTREE root, int item);
int count_nodes(BTREE root, int cnt);
int count_Lnodes(BTREE root, int cnt);
int *makeArray(BTREE root, int val[]);
int *inorder_traversal(int i, BTREE b_tree, int *valPtr);
//int *order_array(int a[]);
void divide_array(int a[], int b[], int c[], int siz);
int find_center(int a[], int siz);
int main()
{
// int command;
BTREE b_tree;
int array_of_ints[] = {5, 10, 2, 5, 7, 12, 3, 9, 8};
int val[9] = {0};
int *valPtr = 0;
b_tree = makeTree(array_of_ints, 0, siz);
printf("Tree printed 'in-order'\n");
preorder (b_tree);
putchar('\n');
printf("Number of nodes = %d\n", count_nodes(b_tree, 0));
printf("Number of Leaf nodes = %d\n", count_Lnodes(b_tree, 0));
printf("Here is the array made from the tree:\n");
valPtr = makeArray(b_tree, val);
return 0;
}
// put an array in alphabetical order
int *order_array(int a[])
{
int j, i, temp;
int *b = a;
for (i = 0; i < siz-1; ++i)
for (j = i+1; j < siz; ++j)
if (a[i] > a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
return b;
}
// put an array in alphabetical order
int *order_array(int a[])
{
int j, i, temp;
int *b = a;
for (i = 0; i < siz-1; ++i)
for (j = i+1; j < siz; ++j)
if (a[i] > a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
return b;
}
#include<stdlib.h>
#include<stdio.h>
struct tree_el {
int val;
struct tree_el * right, * left;
};
typedef struct tree_el node;
void insert(node ** tree, node * item) {
if(!(*tree)) {
*tree = item;
return;
}
if(item->val<(*tree)->val)
insert(&(*tree)->left, item);
else if(item->val>(*tree)->val)
insert(&(*tree)->right, item);
}
void printout(node * tree) {
if(tree->left) printout(tree->left);
printf("%d\n",tree->val);
if(tree->right) printout(tree->right);
}
void main() {
node * curr, * root;
int i;
root = NULL;
for(i=1;i<=10;i++) {
curr = (node *)malloc(sizeof(node));
curr->left = curr->right = NULL;
curr->val = rand();
insert(&root, curr);
}
printout(root);
}
http://www.cs.bu.edu/teaching/c/tree/binary/