
Explain the below given program, How it works?
#include <iostream>
using namespace std;
struct node
{
char data;
struct node *left;
struct node *right;
};
struct node* newNode(char data)
{
struct node *node = new struct node();
node->data = data;
node->left = NULL;
node->right = NULL;
return node;
}
// find and display father node with its child nodes
void Childs(node *root,char D)
{
if(root==NULL)
{
return;
}
if(root->data==D)
{
if(root->left!=NULL&&root->right!=NULL)
{
cout<<root->data<<" is the father of : ";
cout<<root->left->data<<" and "<<root->right->data<<endl;
return;
}
else if(root->left==NULL&&root->right!=NULL)
{
cout<<root->data<<" has only one child i.e. : ";
cout<<root->right->data<<endl;
return;
}
else if(root->left!=NULL&&root->right==NULL)
{
cout<<root->data<<" has only one child i.e. : ";
cout<<root->left->data<<endl;
}
else
{
cout<<root->data<<" Has No Child\n";
return;
}
}
Childs(root->left,D);
Childs(root->right,D);
}
// Display all the tree nodes in one line
void display(node* r)
{
if(r==NULL)
{
return;
}
else
{
display(r->left);
cout<<r->data<<" ";
display(r->right);
}
}
// Display all the tree nodes in 2D form
int COUNT=10;
void Print_2D(node *Root, int space)
{
if (Root == NULL)
{
return;
}
else
{
// Increment of Space between levels
space +=COUNT;
// First Process right child
Print_2D(Root->right, space);
cout<<"\n";
// Adding the spaces
for(int i=COUNT; i<space; i++)
{
cout<<" ";
}
//Display Current Root DATA
cout<<Root->data<<"\n";
// Process left child
Print_2D(Root->left, space);
}
}
int main()
{
/*create root node*/
struct node *rootNode = newNode('A');
rootNode->left = newNode('K');
rootNode->right = newNode('L');
rootNode->left->left = newNode('P');
rootNode->left->right = newNode('Q');
rootNode->right->left = newNode('B');
rootNode->right->right = newNode('C');
rootNode->left->left->left = newNode('J');
rootNode->right->left->left = newNode('X');
rootNode->right->left->right = newNode('Y');
rootNode->right->right->left = newNode('Z');
cout<<"=========================\n";
cout<<"= Display in One Line =\n";
cout<<"=========================\n";
display(rootNode);
cout<<endl<<endl;
cout<<"=========================\n";
cout<<"= Display in 2D =\n";
cout<<"=========================\n";
Print_2D(rootNode,0);
cout<<endl<<endl;
cout<<"================================\n";
cout<<"= Display Father of Childs =\n";
cout<<"================================\n\n";
Childs(rootNode,'A');
Childs(rootNode,'K');
Childs(rootNode,'L');
Childs(rootNode,'P');
Childs(rootNode,'Q');
Childs(rootNode,'B');
Childs(rootNode,'C');
cout<<endl<<endl;
return 0;
}

Step by stepSolved in 3 steps

- Questions: There needs to be a dynamic array of Child that opposes with SCALE and is assigned to "familyTree". The createFamilyTree() function needs to be defined. Please see the C++ code.arrow_forwardC++ Data Structure:Create an AVL Tree C++ class that works similarly to std::map, but does NOT use std::map. In the PRIVATE section, any members or methods may be modified in any way. Standard pointers or unique pointers may be used.** MUST use given Template below: #ifndef avltree_h#define avltree_h #include <memory> template <typename Key, typename Value=Key> class AVL_Tree { public: classNode { private: Key k; Value v; int bf; //balace factor std::unique_ptr<Node> left_, right_; Node(const Key& key) : k(key), bf(0) {} Node(const Key& key, const Value& value) : k(key), v(value), bf(0) {} public: Node *left() { return left_.get(); } Node *right() { return right_.get(); } const Key& key() const { return k; } const Value& value() const { return v; } const int balance_factor() const {…arrow_forwardtypedef _people { int age; char name[ 32 ] ; } People_T ; People_T data [ 3 ]; Using string lib function, Assign 30 and Cathy to the first cell, Assign 40 and John to the second cell and Assign 50 and Tom to the third cell People_T *ptr ; Declare a pointer pointing to the structure data and print the age and name using the pointer. your output can be : 30 Cathy 40 John 50 Tomarrow_forward
- C++ Given code #include <iostream>using namespace std; class Node {public:int data;Node *pNext;}; void displayNumberValues( Node *pHead){while( pHead != NULL) {cout << pHead->data << " ";pHead = pHead->pNext;}cout << endl;} //Option 1: Search the list// TODO: complete the function below to search for a given value in linked lsit// return true if value exists in the list, return false otherwise. ?? linkedlistSearch( ???){ } //Option 2: get sum of all values// TODO: complete the function below to return the sum of all elements in the linked list. ??? getSumOfAllNumbers( ???){ } int main(){int userInput;Node *pHead = NULL;Node *pTemp;cout<<"Enter list numbers separated by space, followed by -1: "; cin >> userInput;// Keep looping until end of input flag of -1 is givenwhile( userInput != -1) {// Store this number on the listpTemp = new Node;pTemp->data = userInput;pTemp->pNext = pHead;pHead = pTemp;cin >> userInput;}cout <<"…arrow_forwardCourse: Data Structure and Algorithims Language: Java Kindly make the program in 2 hours. Task is well explained. You have to make the proogram properly in Java: Restriction: Prototype cannot be change you have to make program by using given prototype. TAsk: Create a class Node having two data members int data; Node next; Write the parametrized constructor of the class Node which contain one parameter int value assign this value to data and assign next to null Create class LinkList having one data members of type Node. Node head Write the following function in the LinkList class publicvoidinsertAtLast(int data);//this function add node at the end of the list publicvoid insertAthead(int data);//this function add node at the head of the list publicvoid deleteNode(int key);//this function find a node containing "key" and delete it publicvoid printLinkList();//this function print all the values in the Linklist public LinkListmergeList(LinkList l1,LinkList l2);// this function…arrow_forwarduse code below in part with bts #include <stdio.h>#include <stdlib.h>#include <time.h> typedef struct node_struct {int item;struct node_struct *next;} node; /*** 10->NULL* We want to insert 20* First call ([10], 20) [not complete]* {10, {20, NULL}} To compute the conditional probabilities you need to determine unigram andbigram counts first (you can do this in a single pass through a file if you do thingscarefully) and store them in a Binary Search Tree (BST). After that, you can computethe conditional probabilities.Input filesTest files can be found on (http://www.gutenberg.org/ebooks/). For example,search for “Mark Twain.” Then click on any of his books. Next download the “PlainText UTF-8” format.In addition, you should test your program on other input files as well, for which youcan hand-compute the correct answer.Output filesYour program must accept the name of an input file as a command line argument.Let's call the file name of this file fn. Your program must…arrow_forward
- Given the following declaration : char msg[100] = "Department of Computer Science"; What is printed by: strcpy_s(msg, "University"); int len = strlen(msg); for (int i = len-3; i >0; i--) { msg[i] = 'x'; } cout << msg;arrow_forwardİn C Language pls help #include <stdio.h>#include <stdlib.h>#include <string.h> typedef struct ArrayList_s{ void **list; int size; int capacity; int delta_capacity;} ArrayList_t, *ArrayList; ArrayList arraylist_create(int capacity, int delta_capacity){ ArrayList l; l = (ArrayList)malloc(sizeof(ArrayList_t)); if (l != NULL) { l->list = (void **)malloc(capacity * sizeof(void *)); if (l->list != NULL) { l->size = 0; l->capacity = capacity; l->delta_capacity = delta_capacity; } else { free(l); l = NULL; } } return l;} void arraylist_destroy(ArrayList l){ free(l->list); free(l);} int arraylist_isempty(ArrayList l){ return l->size == 0;} int arraylist_isfull(ArrayList l){ return l->size == l->capacity;} int arraylist_set(ArrayList l, void *e, int index, void **replaced){ if (!arraylist_isfull(l)) {…arrow_forward#include using namespace std; struct ListNode { string data; ListNode *next; }; int main() { ListNode *p, *list; list = new ListNode; list->data = "New York"; p new ListNode; p->data = "Boston"; list->next = p; p->next = new ListNode; p->next->data = "Houston"; p->next->next = nullptr; // new code goes here Which of the following code correctly deletes the node with value "Boston" from the list when added at point of insertion indicated above? O list->next = p; delete p; O p = list->next; %3D list->next = p->next; delete p; p = list->next; list = p->next; delete p; O None of these O p = list->next; %3D list->next = p; %3D delete p;arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





