605
.pdf
keyboard_arrow_up
School
University of Texas *
*We aren’t endorsed by this school
Course
CS201
Subject
Computer Science
Date
Apr 30, 2024
Type
Pages
4
Uploaded by msway on coursehero.com
1.)
// Initializes the tree with a specified size and sets the root to -1
FUNCTION makeTree(size)
tree = new TreeNode[size]
root = -1
// Creates a new TreeNode with the given item and initializes children to -1
FUNCTION createNode(item)
node = new TreeNode()
node.item = item
node.leftChild = -1
node.rightChild = -1
node.isThread = false
RETURN node
// Sets the left child of a given parent node to a new node with the specified item
FUNCTION setLeft(parentIndex, item)
leftIndex = 2 * parentIndex + 1
tree[leftIndex] = createNode(item)
tree[parentIndex].leftChild = leftIndex
// Sets the right child of a given parent node to a new node with the specified item
// In addition, if isThread is true, it marks the rightChild as a thread rather than a normal child node
FUNCTION setRight(parentIndex, item, isThread)
rightIndex = 2 * parentIndex + 2
IF NOT isThread
tree[rightIndex] = createNode(item)
tree[parentIndex].rightChild = rightIndex
ELSE
tree[parentIndex].rightChild = rightIndex
tree[parentIndex].isThread = true
// Creates the root of the tree with the specified item
FUNCTION makeTreeWithRoot(item)
IF root == -1
tree[0] = createNode(item)
root = 0
2.)
FUNCTION inOrderTraversal(rootIndex)
IF rootIndex == -1
RETURN
// Find the leftmost node first
currentNodeIndex = findLeftmost(rootIndex)
WHILE currentNodeIndex != -1
visit(tree[currentNodeIndex])
// If the right child is a thread, follow it to the next node in in-order sequence
IF tree[currentNodeIndex].isThread
currentNodeIndex = tree[currentNodeIndex].rightChild
ELSE
// If not a thread, find the leftmost node of the right child to continue traversal
currentNodeIndex = findLeftmost(tree[currentNodeIndex].rightChild)
// Loop continues until all the nodes are visited
// Finds the leftmost node starting from a given node index
FUNCTION findLeftmost(nodeIndex)
WHILE nodeIndex != -1 AND tree[nodeIndex].leftChild != -1
nodeIndex = tree[nodeIndex].leftChild
RETURN nodeIndex
FUNCTION visit(node)
//Whatever you want to do with that node
3.)
// A = array with data values
FUNCTION sortUsingCount(A)
n = LENGTH(A)
DECLARE Count[n]
DECLARE Output[n]
// Create a count array for the length
FOR i FROM 0 TO n - 1
Count[i] = 0
// THIS IS IMPORTANT: Count the number of items smaller than each A[i], we need to check if it’s
smaller
FOR i FROM 0 TO n - 1
FOR j FROM 0 TO n - 1
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
Define a function called get_predecessor()
which takes a Node object and a value as
parameters. The function should search the chain of nodes starting at the parameter node and
returns the node which comes before the node containing the parameter value. If the
parameter value is NOT in the chain of nodes or the parameter value is in the first node of the
chain, the function returns None.
arrow_forward
Assume the tree node structure is following........
struct node
{
int data;
struct node* left;
struct node* right;
};
struct node *root = null;
and there is a created new node function, called newnode(int new_data).
Please filled the Blank of Insertion function.
void insert(struct node *root, int key) {
struct node *current;
queue q;
q.enque(root);
while(!q.empty()
}
current = q.front();
q.deque();
if(current->left == NULL) {
break;
}
else
}
q.enque(
if(current->right == NULL) {
break;
else
q.enque(_
= newnode(key);
= newnode(key);
_-));
arrow_forward
typedef struct node{int data;struct node *left,*right;}BST;The node structure of BST is shown above. Please design an efficient algorithm to return the maximum keyword value in BST. Completion function: int findmax (BST *T)
arrow_forward
A BST is constructed in the usual way using the node definition below. Write a function
int child2( bst node t *curr)
that returns the number of nodes that have 2 children.
typedef struct BST NODE T {int data;struct BST NODE T *left, *right;
} bst node t;
int child2( bst node t *curr){
}
arrow_forward
Define a function called get_predecessor()
which takes a Node object and a value as
parameters. The function should search the chain of nodes starting at the parameter node and
returns the node which comes before the node containing the parameter value. If the
parameter value is NOT in the chain of nodes or the parameter value is in the first node of the
chain, the function returns None.
Test:
x = Node('hello')
y = Node('world')
z = Node('goodbye')
x.set_next(y)
y.set_next(z)
print (get_predecessor (x, 'goodbye'))
Output:
world
Test:
x= Node('hello')
y Node('world')
z = Node('goodbye')
x.set_next(y)
y.set_next(z)
print(get_predecessor(x, 'hello'))
Ouput:
None
arrow_forward
C++ DATA STRUCTURES
Implement the TNode and Tree classes. The TNode class will include a data item name of type string,which will represent a person’s name. Yes, you got it right, we are going to implement a family tree!Please note that this is not a Binary Tree.
Write the methods for inserting nodes into the tree,searching for a node in the tree, and performing pre-order and post-order traversals.The insert method should take two strings as input. The second string will be added as a child node tothe parent node represented by the first string.
Hint:
The TNode class will need to have two TNode pointers in addition to the name data member:TNode *sibling will point to the next sibling of this node, and TNode *child will represent the first child ofthis node. You see two linked lists here??? Yes! You’ll need to use the linked lists
arrow_forward
C++ Data Structures (Binary Trees)- Write the definition of the function nodeCount that returns the number of nodes in the binary tree. Add this function to the class binaryTreeType and create a program to test this function. Here are the headers:
binaryTree.h
//Header File Binary Search Tree
#ifndef H_binaryTree
#define H_binaryTree
#include <iostream>
using namespace std;
//Definition of the Node
template <class elemType>
struct nodeType
{
elemType info;
nodeType<elemType> *lLink;
nodeType<elemType> *rLink;
};
//Definition of the class
template <class elemType>
class binaryTreeType
{
public:
const binaryTreeType<elemType>& operator=
(const binaryTreeType<elemType>&);
//Overload the assignment operator.
bool isEmpty() const;
//Function to determine whether the binary tree is empty.
//Postcondition: Returns true if the binary tree is empty;
// otherwise, returns false.
void inorderTraversal() const;
//Function to do an inorder…
arrow_forward
2-) In a double linked list, the structure of a node is defined as follows:
struct node {
int employeeNo;
char name[20];
struct node *next;
structnode *prev;
}node;
the nodes in the list are sorted according to employeeNo in ascending order (from smaller to larger ).
Write a function to insert a node with a given name and employeeNo into the list so that the list will
remain the sorted. employeeNo değerine göre kiüçükten büyüğe sıralanmış bir çift bağlı liste olsun.
Verilen bir isim ve employeeNo değerine sahip düğümü listeye sıra bozulmayacak şekilde ekleyen bir
fonksyion yazınız.
arrow_forward
Language/Type:
C++ binary trees pointers recursion
Write a function named hasPath that interacts with a tree of BinaryTreeNode structures representing an unordered binary tree. The function accepts three parameters: a pointer to the root of the tree, and two integers start and end, and returns true if a path can be found in the tree from start down to end. In other words, both start and end must be element data values that are found in the tree, and end must be below start, in one of start's subtrees; otherwise the function returns false. If start and end are the same, you are simply checking whether a single node exists in the tree with that data value. If the tree is empty, your function should return false.
For example, suppose a BinaryTreeNode pointer named tree points to the root of a tree storing the following elements. The table below shows the results of several various calls to your function:
67
88
52
1
21
16
99
45
Call
Result
Reason
hasPath(tree,
67, 99)
true
path exists…
arrow_forward
C Programming language
Part 1: You need to define a data structure for a doubly linked list and a binary search tree. Also, you need to implement the following functions:
Insert Sorted
LINKEDLIST insertSorted(LINKEDLIST head, int num): head points to the first node in the sorted linked list; num is a number to be inserted in in correct place in the linked list pointed at “head”. The linked list should be sorted after inserting “num”. This function returns the head of the modified head.
BSTREE insert(BSTREE root, int num): root points to a node in a binary search tree; num is a number to be inserted in the tree rooted at “root”. This function returns the root of the modified tree.
Find an element
LINKEDLIST find(LINKEDLIST head,int num): head points to the first node of a linked list; num is a number to be searched for in the linked list started at “head”. This function returns a pointer to the node containing “num” or NULL if num is not found
BSTREE find(BSTREE root,int…
arrow_forward
struct remove_from_front_of_dll {
// Function takes no parameters, removes the book at the front of a doubly
// linked list, and returns nothing.
void operator()(const Book& unused) {
//// TO-DO (13) ||||
// Write the lines of code to remove the book at the front of "my_dll",
//
// Remember, attempting to remove an element from an empty data structure is
// a logic error. Include code to avoid that.
///// END-TO-DO (13) ////
}
std::list& my_dll;
};
arrow_forward
struct insert_at_back_of_dll {
// Function takes a constant Book as a parameter, inserts that book at the
// back of a doubly linked list, and returns nothing.
void operator()(const Book& book) {
/ // TO-DO (2) ||||
// Write the lines of code to insert "book" at the back of "my_dll".
//
// // END-TO-DO (2) |||
}
std::list& my_dll;
};
arrow_forward
Write the following function:
The function gets a root of a Binary Tree of ints, and a function f. it applies f to the data of each node in the tree.
// applies f to each node of the tree under root
void map(BTnode_t* root, int (*f)(int));
struct BTnode {
int value;
struct BTnode*left;
struct BTnode*right;
struct BTnode*parent;
};
typedef struct BTnode BTnode_t;
BTNODE.C:
BTnode_t* create_node(int val) {
BTnode_t* newNode = (BTnode_t*) malloc(sizeof(BTnode_t));
newNode->value = val;
newNode->left = NULL;
newNode->right = NULL;
newNode->parent = NULL;
returnnewNode;
}
void set_left_child(BTnode_t* parent, BTnode_t* left_child) {
if (parent)
parent->left = left_child;
if (left_child)
left_child->parent = parent;
}
void set_right_child(BTnode_t* parent, BTnode_t* right_child) {
if (parent)
parent->right = right_child;
if (right_child)
right_child->parent = parent;
}
void print_pre_order(BTnode_t* root) {
if (root == NULL)
return;
printf("%d ",…
arrow_forward
Course: Data Structure and Algorithms
Language: C++
Question is well explained
Question #2Implement a class for Circular Doubly Linked List (with a dummy header node) which stores integers in unsorted order. Your class definitions should look like as shown below:
class CDLinkedList;class DNode {friend class CDLinkedList;private int data;private DNode next;private DNode prev;};class CDLinkedList
{private:DNode head; // Dummy header nodepublic CDLinkedList(); // Default constructorpublic bool insert (int val); public bool removeSecondLastValue (); public void findMiddleValue(); public void display(); };
arrow_forward
Data structures
HW3
Q1. Consider the code for displayList() function shown below:
void displayList(void)
{
Node* currNode = head;
while (currNode != NULL)
{
coutitemnext;
a) Modify it to create a new function displayNodeNum() that will display the number
of nodes in the list, e.g., if there are three nodes, it should display "3 nodes in the
list". If the list is empty then it should display “the list is empty right now". [Hint:
you need only add 2 or 3 lines to it.]
b) Modify the displayList() or displayNodeNum() function created above to create a
new function sumNodeValues() that will display the total of the values of the nodes,
e.g. if there are 4 nodes having values 1, 3, 8, 10 then it should display “The sum is
22". [Hint: you need only add 3 or 4 lines to the first function.]
c) Create a function findValue(int) that will take a value and display it if it is in the list,
e.g. the user enters 3. The function will search 3 in the list. If it is there, it will print
"Number 3 is in…
arrow_forward
Multiple choice in data structures
void doo(node<int>*root){
if(root !=0) { node<int>*p=root;
while(root->next!=0) root=root->next;
p->data=root->data;
}
What is this code do?
a.
swap the first item with the last item in the linked list
b.
set the first item in the linked list as the last item
c.
doesn't do anything because the root parameter is passed by value
d.
change the root item in the binary tree with the farthest leaf item
arrow_forward
Modify the given code to accept float instead of int as a coefficient in C LANGUAGE:
// Node structure containing power and coefficient of// variablestruct Node {int coeff;int pow;struct Node* next;};
// Function to create new nodevoid create_node(int x, int y, struct Node** temp){struct Node *r, *z;z = *temp;if (z == NULL) {r = (struct Node*)malloc(sizeof(struct Node));r->coeff = x;r->pow = y;*temp = r;r->next = (struct Node*)malloc(sizeof(struct Node));r = r->next;r->next = NULL;}else {r->coeff = x;r->pow = y;r->next = (struct Node*)malloc(sizeof(struct Node));r = r->next;r->next = NULL;}}
// Function Adding two polynomial numbersvoid polyadd(struct Node* poly1, struct Node* poly2,struct Node* poly){while (poly1->next && poly2->next) {// If power of 1st polynomial is greater then 2nd,// then store 1st as it is and move its pointerif (poly1->pow > poly2->pow) {poly->pow = poly1->pow;poly->coeff = poly1->coeff;poly1 =…
arrow_forward
in c++, write a function to find the height of a specific node in a Binary Search Tree.
arrow_forward
Provide a detailed explanation line by line. Explain how this C++ program functions
Source Codes
#include
using namespace std;
// Node struct to hold data and pointer to next node
struct Node {
int data;
Node* next;
};
// Linked List class
class LinkedList {
private:
Node* head; // pointer to head node
public:
LinkedList() {
head = NULL; // initialize head to NULL
}
// Insert a new node at the front of the list
void insert(int value) {
Node* newNode = new Node(); // create a new node
newNode->data = value; // set the data of the new node to the input value
newNode->next = head; // set the next pointer of the new node to the current head node
head = newNode; // set the head pointer to the new node
}
// Delete a node with a specific value from the list
void deleteNode(int value) {
Node* current = head; // set a pointer to the current node
Node* previous = NULL; // set a pointer…
arrow_forward
Write the definition of the function nodeCount that returns the number of nodes in the binary tree and Add this function to the class binaryTreeType and create a program to test this function.
USE THIS FILE FOR YOUR PROGRAM
USE THIS FILE TO TEST YOUR PROGRAM
#include <iostream> //Line 1#include "binarySearchTree.h" //Line 2using namespace std; //Line 3void print(int& x); //Line 4void update(int& x); //Line 5int main() //Line 6{ //Line 7bSearchTreeType<int> treeRoot; //Line 8int num; //Line 9 cout << "Line 10: Enter numbers ending "<< "with -999." << endl; //Line 10cin >> num; //Line 11while (num != -999) //Line 12{ //Line 13treeRoot.insert(num); //Line 14cin >> num; //Line 15} //Line 16cout << endl << "Line 17: Tree nodes in inorder: "; //Line 17treeRoot.inorderTraversal(print); //Line 18cout << endl << "Line 19: Tree Height: "<< treeRoot.treeHeight()<< endl << endl; //Line 19cout <<…
arrow_forward
Define the 3 bolded functions for the following DynIntStack (linked list):
class DynIntStack {private: struct Node { int value; // Value in the node Node *next; // Pointer to the next node }; Node *top; // Pointer to the stack toppublic: DynIntStack() { head = nullptr; } void push(int); //assume this is already defined void removeTop(); // removes the top element without returning it int topValue(); // returns the top element without removing it bool isEmpty() { return head == nullptr; } bool isFull() { return false; } void pushMany(int values[], int n); //add n values from the array};
Hints:
void removeTop() (hint 3 lines of code)
int topValue() (hint 1 line of code)
void pushMany(int values[], int n) (hint 2 lines of code, use a for loop, call another function)
arrow_forward
struct node{
int a;
struct node * nextptr;
};
Write two functions. One for inserting new values to a link list that uses the given node structure.
void insert(struct node **head, int value);
Second function is called to count the number of even numbers in the link list. It returns an integer that represents the number of even numbers.
int countEvenNumbers(struct node *head);
Write a C program that reads a number of integers from the user and insert those integers into a link list (use insert function). Later pass the head pointer of this link list to a function called countEvenNumbers. This function counts and returns the number of even numbers in the list. The returned value will be printed on the screen.
Note 1: Do not modify the function prototypes.
Sample Input1:
Sample Output1:
45 23 44 12 37 98 33 35 -1
3
Sample Input2:
Sample Output2:
11 33 44 21 22 99 123 122 124 77 -1
4
arrow_forward
Use the following node definition for this problem.struct NodeInt32{int32_t value; NodeInt32* next;}
Write a function which searches a non-empty linked list for a target value. Its exact signature should be:
NodeInt32* find(NodeInt32* head, int32_t target);
The function should return the first node whose value equals target. If the target is not found in the list, then the function should return NULL.
arrow_forward
Graphs: Depth First Traversal
Starting with the same graph program as last assignment, implement a depth first traversal method. Test iy on nodes 1, 2, and 3 as start nodes.
Graph program:
#include <iostream>#include <vector>#include <string>using namespace std;
class Edge;//-------------------------------------------------------------////class Node{public:Node(string iname){name = iname;}string name;int in_count = 0;bool visited = false; vector<Edge *> out_edge_list;};//-------------------------------------------------------------////class Edge{public:Edge(string iname, double iweight, Node *ifrom, Node *ito){name = iname;weight = iweight;from = ifrom;to = ito;}
string name;double weight;Node *from;Node *to;bool visited = false;};
//-------------------------------------------------------------////class Graph{public:vector<Node *> node_list;vector<Edge *> edge_list; //----------------------------------------------------------//Node*…
arrow_forward
Write C code that implements a soccer team as a linked list.
1. Each node in the linkedlist should be a member of the team and should contain the following information:
What position they play
whether they are the captain or not
Their pay
2. Write a function that adds a new members to this linkedlist at the end of the list.
arrow_forward
The function that will a single items to the list is
Oextend (...)
Oadd(...)
Oappend(...)
Olengthen(...)
arrow_forward
Suppose a node of a doubly linked list is defined as follows:
struct Node{
int data;
struct Node* next;
struct Node* prev;
};
Write the function definition of the function deleteElement as presented below. This function deletes a node at position n from a doubly linked list.
struct Node* deleteElement(struct Node* head, int n){
//write the function definition
}
arrow_forward
C++ PROGRAMMINGTopic: Binary Search Trees
Explain the c++ code below.: SEE ATTACHED PHOTO FOR THE PROBLEM INSTRUCTIONS It doesn't have to be long, as long as you explain what the important parts of the code do. (The code is already implemented and correct, only the explanation needed)
node* left(node* p) {
return p->left;
}
node* right(node* p) {
return p->right;
}
node* sibling(node* p){
if(p != root){
node* P = p->parent;
if(left(P) != NULL && right(P) != NULL){
if(left(P) == p){
return right(P);
}
return left(P);
}
}
return NULL;
}
node* addRoot(int e) {
if(size != 0){
cout<<"Error"<<endl;
return NULL;
}
root = create_node(e,NULL);
size++;
return root;
}
node* addLeft(node* p, int e) {…
arrow_forward
SKELETON CODE IS PROVIDED ALONG WITH C AND H FILES.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "node.h"
#include "stack_functions.h"
#define NUM_VERTICES 10
/** This function takes a pointer to the
adjacency matrix of a Graph and the
size of this matrix as arguments and
prints the matrix
*/
void print_graph(int * graph, int size);
/** This function takes a pointer to the
adjacency matrix of a Graph, the size
of this matrix, the source and dest
node numbers along with the weight or
cost of the edge and fills the adjacency
matrix accordingly.
*/
void add_edge(int * graph, int size, int src, int dst, int cost);
/** This function takes a pointer to the adjacency matrix of
a graph, the size of this matrix, source and destination
vertex numbers as inputs and prints out the path from the
source vertex to the destination vertex. It also prints
the total cost of this…
arrow_forward
Computer Science
JAVA Write a program that maintains the names of your friends and relatives and thus serves as a friends list.
You should be able to enter, delete, modify, or search this data. You should assume that the names are unique.
use a class to represent the names in the friends list and another class to represent the friends list itself. This class should contain a Binary Search Tree of names as a data field.
(TreeNode Class
BinarySearchTree Class
FriendsList Class)
arrow_forward
C Programming Language
If you have the following node declaration:Homework 3struct Node {int number;struct Node * next;};typedef struct Node node;node *head,*newNode;Write a C program that contains the following functions to manipulate this linked list :1. First function: Adding the odd numbers to the beginning of the list and even numbers to theend of the list until -1 is entered from keyboard.2. Second function using given prototype below. This function cuts the last node of the list andadds it to the beginning as first node. It takes beginning address of the list as a parameter andreturns the updated list.node* cutlastaddhead(node* head);3. 3rd function deletes the element in the middle of the list (free this memory location) (if the listhas 100 or 101 elements, it will delete the 50th element). The function will take a list as aparameter and return the updated list.4. 4th function named changeFirstAndLast that swaps the node at the end of the list and thenode at the beginning of…
arrow_forward
Design data structures: present five data structures including B-tree for big data (you find data), for sorting algorithms. In this
project, you will implement and analyze the following.
Median finding, Order Statistics, and Quick Sort: In this project, you will implement the median-finding algorithms. The
user should be able to select the "k”, i.e., the rank of the number desired as output (k = n/2 is the median). You should also
be able to select groups of 3, 5, 7, etc. in the linear-time median finding algorithm and be able to compare the performance
of each. Also, implement the randomized median finding algorithm and compare it against the linear-time one. Implement
quick sorting using both algorithms and compare the performances of these different versions.
arrow_forward
#include <bits/stdc++.h>
using namespace std;
// Structure of a Node
struct Node
{
int data;s
struct Node *next;
struct Node *prev;
};
// Function to insert at the end
void insertEnd(struct Node** start, int value)
{
// If the list is empty, create a single node
// circular and doubly list
if (*start == NULL)
{
struct Node* new_node = new Node; new_node->data = value;
new_node->next = new_node->prev = new_node;
*start = new_node;
return;
}
// If list is not empty
/* Find last node */
Node *last = (*start)->prev;
// Create Node dynamically
struct Node* new_node = new Node;
new_node->data = value;
// Start is going to be next of new_node
new_node->next = *start;
// Make new node previous of start
(*start)->prev = new_node;
// Make last preivous of new node
new_node->prev = last;
// Make new node next of old last
last->next = new_node;
}
// Function to insert Node at the beginning
// of the List,
void insertBegin(struct…
arrow_forward
Topic: Doubly Linked List Deque
Implement the following problem in the main case 0 (see attached photo)
Your algorithm for the hierarchy problem should follow this: Evaluate the final set of operations first given the set of rules. Then, do the remove operations. Finally, do the add operations.
DO NOT MIND THE #include "dlldeque.h" it is already implemented only the case 0 needs to be solved
#include <iostream>
#include <cstring>
#include "dlldeque.h"
using namespace std;
int main(int argc, char** argv) {
DLLDeque* deque = new DLLDeque();
int test;
cin >> test;
switch (test) {
case 0:
// perform your Hierarchy implementation here
// utilize the deque initialized,
// initialize variables you need before switch
// you can use the print() method to debug, but not the final_print()
// do not modify from this point onwards
deque->final_print();…
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Related Questions
- Define a function called get_predecessor() which takes a Node object and a value as parameters. The function should search the chain of nodes starting at the parameter node and returns the node which comes before the node containing the parameter value. If the parameter value is NOT in the chain of nodes or the parameter value is in the first node of the chain, the function returns None.arrow_forwardAssume the tree node structure is following........ struct node { int data; struct node* left; struct node* right; }; struct node *root = null; and there is a created new node function, called newnode(int new_data). Please filled the Blank of Insertion function. void insert(struct node *root, int key) { struct node *current; queue q; q.enque(root); while(!q.empty() } current = q.front(); q.deque(); if(current->left == NULL) { break; } else } q.enque( if(current->right == NULL) { break; else q.enque(_ = newnode(key); = newnode(key); _-));arrow_forwardtypedef struct node{int data;struct node *left,*right;}BST;The node structure of BST is shown above. Please design an efficient algorithm to return the maximum keyword value in BST. Completion function: int findmax (BST *T)arrow_forward
- A BST is constructed in the usual way using the node definition below. Write a function int child2( bst node t *curr) that returns the number of nodes that have 2 children. typedef struct BST NODE T {int data;struct BST NODE T *left, *right; } bst node t; int child2( bst node t *curr){ }arrow_forwardDefine a function called get_predecessor() which takes a Node object and a value as parameters. The function should search the chain of nodes starting at the parameter node and returns the node which comes before the node containing the parameter value. If the parameter value is NOT in the chain of nodes or the parameter value is in the first node of the chain, the function returns None. Test: x = Node('hello') y = Node('world') z = Node('goodbye') x.set_next(y) y.set_next(z) print (get_predecessor (x, 'goodbye')) Output: world Test: x= Node('hello') y Node('world') z = Node('goodbye') x.set_next(y) y.set_next(z) print(get_predecessor(x, 'hello')) Ouput: Nonearrow_forwardC++ DATA STRUCTURES Implement the TNode and Tree classes. The TNode class will include a data item name of type string,which will represent a person’s name. Yes, you got it right, we are going to implement a family tree!Please note that this is not a Binary Tree. Write the methods for inserting nodes into the tree,searching for a node in the tree, and performing pre-order and post-order traversals.The insert method should take two strings as input. The second string will be added as a child node tothe parent node represented by the first string. Hint: The TNode class will need to have two TNode pointers in addition to the name data member:TNode *sibling will point to the next sibling of this node, and TNode *child will represent the first child ofthis node. You see two linked lists here??? Yes! You’ll need to use the linked listsarrow_forward
- C++ Data Structures (Binary Trees)- Write the definition of the function nodeCount that returns the number of nodes in the binary tree. Add this function to the class binaryTreeType and create a program to test this function. Here are the headers: binaryTree.h //Header File Binary Search Tree #ifndef H_binaryTree #define H_binaryTree #include <iostream> using namespace std; //Definition of the Node template <class elemType> struct nodeType { elemType info; nodeType<elemType> *lLink; nodeType<elemType> *rLink; }; //Definition of the class template <class elemType> class binaryTreeType { public: const binaryTreeType<elemType>& operator= (const binaryTreeType<elemType>&); //Overload the assignment operator. bool isEmpty() const; //Function to determine whether the binary tree is empty. //Postcondition: Returns true if the binary tree is empty; // otherwise, returns false. void inorderTraversal() const; //Function to do an inorder…arrow_forward2-) In a double linked list, the structure of a node is defined as follows: struct node { int employeeNo; char name[20]; struct node *next; structnode *prev; }node; the nodes in the list are sorted according to employeeNo in ascending order (from smaller to larger ). Write a function to insert a node with a given name and employeeNo into the list so that the list will remain the sorted. employeeNo değerine göre kiüçükten büyüğe sıralanmış bir çift bağlı liste olsun. Verilen bir isim ve employeeNo değerine sahip düğümü listeye sıra bozulmayacak şekilde ekleyen bir fonksyion yazınız.arrow_forwardLanguage/Type: C++ binary trees pointers recursion Write a function named hasPath that interacts with a tree of BinaryTreeNode structures representing an unordered binary tree. The function accepts three parameters: a pointer to the root of the tree, and two integers start and end, and returns true if a path can be found in the tree from start down to end. In other words, both start and end must be element data values that are found in the tree, and end must be below start, in one of start's subtrees; otherwise the function returns false. If start and end are the same, you are simply checking whether a single node exists in the tree with that data value. If the tree is empty, your function should return false. For example, suppose a BinaryTreeNode pointer named tree points to the root of a tree storing the following elements. The table below shows the results of several various calls to your function: 67 88 52 1 21 16 99 45 Call Result Reason hasPath(tree, 67, 99) true path exists…arrow_forward
- C Programming language Part 1: You need to define a data structure for a doubly linked list and a binary search tree. Also, you need to implement the following functions: Insert Sorted LINKEDLIST insertSorted(LINKEDLIST head, int num): head points to the first node in the sorted linked list; num is a number to be inserted in in correct place in the linked list pointed at “head”. The linked list should be sorted after inserting “num”. This function returns the head of the modified head. BSTREE insert(BSTREE root, int num): root points to a node in a binary search tree; num is a number to be inserted in the tree rooted at “root”. This function returns the root of the modified tree. Find an element LINKEDLIST find(LINKEDLIST head,int num): head points to the first node of a linked list; num is a number to be searched for in the linked list started at “head”. This function returns a pointer to the node containing “num” or NULL if num is not found BSTREE find(BSTREE root,int…arrow_forwardstruct remove_from_front_of_dll { // Function takes no parameters, removes the book at the front of a doubly // linked list, and returns nothing. void operator()(const Book& unused) { //// TO-DO (13) |||| // Write the lines of code to remove the book at the front of "my_dll", // // Remember, attempting to remove an element from an empty data structure is // a logic error. Include code to avoid that. ///// END-TO-DO (13) //// } std::list& my_dll; };arrow_forwardstruct insert_at_back_of_dll { // Function takes a constant Book as a parameter, inserts that book at the // back of a doubly linked list, and returns nothing. void operator()(const Book& book) { / // TO-DO (2) |||| // Write the lines of code to insert "book" at the back of "my_dll". // // // END-TO-DO (2) ||| } std::list& my_dll; };arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education