Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program to build a tree and print it using different traversals. The program will be invoked as P0 [ file ] where file

Write a program to build a tree and print it using different traversals. The program will be invoked as

P0 [file] where file is an optional argument.

If the file argument is not given the program reads data from the keyboard as a device (10%) up to end of the file.

If the argument is given, the program reads data file file.fs182. (note that file is any name and the extension is implicit).

Example invocations:

P0 // read from the keyboard until simulated EOF P0 < somefile // same as above except redirecting from somefile instead of keyboard, testing keyboard input P0 somefile // read from somefile.fs182

Assume you do not know the size of the input file

Assume the input data is all strings separated with standard WS separators (space, tab, new line)

If the input file is not readable for whatever reason, or command line arguments are not correct, the program will abort with an appropriate message

The program will read the data left to right and put them into a tree, which is a binary search tree (BST) with respect to the first character of the string (that is strings of the same first character are considered the same data). Letter cases are the same.

Tree is never balanced nor restructured other than growing new nodes

A node should contain all data that falls into the node except that literally the same strings will show up only once (set)

**IMPORTANT**

The program will subsequently output 3 files corresponding to the 3 traversals, named file.preorder, file.inorder and file.postorder. Note that file is the name of the input file if given, and it is 'out' if the input is from the keyboard.

Treversals:

preorder

inorder

postoder

Have the following functions minimum in addition to the main function (the types and arguments are just suggested, the names are required) node_t *buildTree(FILE *); void traverseInorder(node_t*, const char[]); // parameters: tree root, and output basefilename void traversePreorder(node_t*, const char[]); void traversePostorder(node_t*, const char[]);

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_2

Step: 3

blur-text-image_3

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

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

Students also viewed these Databases questions

Question

[Hint: Consider the continuous case with f(x, y) fX(x) fY(y).]

Answered: 1 week ago

Question

8.10 Explain several common types of training for special purposes.

Answered: 1 week ago