Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is in C++ and I need it as soon as possible 4. [30 marks] (Binary tree) Write 1) a non-recursive function to list out

image text in transcribed

image text in transcribed

This is in C++ and I need it as soon as possible

4. [30 marks] (Binary tree) Write 1) a non-recursive function to list out the nodes of a binary tree in preorder, 2) a function to list out the nodes of a binary tree in level- order or breadth first order, that is, to visit the nodes level by level, in each level visit the nodes from left to right. These functions take a pointer to the root node of a tree, and the function prototypes are shown below // funcs.cpp # include #include "Stack.h" #include "Queue . h" using namespace std; template struct BinaryNode T element; BinaryNode left; BinaryNode right; BinaryNode (const T& d T) element (d) left-nullptr; right nullptr; //print the elements of binary tree in preorder template void preorder (BinaryNode void breadth first (BinaryNode* root) // add your code 3) Write an application program a3q4.cpp that contains a create_binary_tree ) function which create the following binary tree (refer to lab 6 exercise click the link). contains main) function which call create binary tree ) function to create a binary tree, and then call preorder and breadth_first functions to print the nodes in preorder and level order, respectively Five files should be submitted for this program question. 1) the stack and queue class templates Stack.h and Queue.h, 2) the file funcs.cpp which contains the implementation of functions, 3) the application file a3q4.cpp containing main ) function, 4)a script file a3q4result containing result Here are the sample runs The preorder: A B D G ICE H J K F The level order: A B C DE F G HIJ K

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

Data Science For Dummies

Authors: Lillian Pierson ,Jake Porway

2nd Edition

1119327636, 978-1119327639

More Books

Students also viewed these Databases questions

Question

When will I do them?

Answered: 1 week ago