Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help writing this code in C programming code: ?Binary Tree Notes/Pseudo Code: Binary Tree: A binary tree is either empty or consists of a

Need help writing this code in C programming code:

?Binary Tree Notes/Pseudo Code: "Binary Tree: A binary tree is either empty or consists of a single vertex and two disjoint subsets each of which is also a binary tree. Structure of a Binary Tree: typedef struct treenode { int data; struct treenode *left, *right; } *binarytree; Declaring a binary tree: binarytree root; Initialize a binary tree: use pass by reference set root to NULL Checking for empty tree: use pass by value if root is NULL, then tree is empty Checking for full tree: use pass by value can we allocate memory the size of a treenode structure? Adding to a tree: assuming tree is NOT full use pass by reference if current position is empty allocate memory the size of a tree node structure put data in it set both left and right children to NULL otherwise (keep looking for empty spot) if data to add is <= current node's data use recursive call to add to left subtree... add(&(*t)->left, datatoadd) otherwise use recursive call to add to right subtree Deleting from a tree: assuming tree is NOT empty and user has specified data to be removed use pass by reference to send tree and pass by value to send data to be removed if not empty if current node is data we are looking for: if no children set temp to (*t) set (*t) to NULL free temp if left child only set temp to (*t) move (*t) to left child free temp if right child only set temp to (*t) move (*t) to right child free temp if two children EITHER (attach left child to left most pointer of right subtree) set temp to (*t)-> right while temp->left != NULL move temp to left subtree set temp->left to (*t)->left move temp back to (*t) move (*t) to (*t)->right free temp OR (attach right child to right most pointer of left subtree set temp to (*t)->left while temp->right != NULL move temp to right subtree set temp->right to (*t)->right move temp back to (*t) move (*t) to (*t)->left free temp otherwise if data we are looking for is <= current data call delete recursively sending left subtree and data to remove otherwise call delete recursively sending right subtree and data to remove otherwise data not in the tree (reached bottom without finding it) Printing the contents of the binary tree: Assuming you've already checked to make sure the tree isn't empty or printed the appropriate message in main, you will pass the tree using pass-by-value since no changes will be made. LNR (Left, Node, Right) / Ascending Order if the tree is not empty call LNR recursively sending the left subtree print the data portion of the current node call LNR recursively sending the right subtree RNL (Right, Node, Left) / Descending Order if the tree is not empty call RNL recursively sending the right subtree print the data portion of the current node call RNL recursively sending the left subtree?"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions

Question

LO2 Discuss important legal areas regarding safety and health.

Answered: 1 week ago