Write a program based on Figs. 20.20–20.22 that inputs a line of text, tokenizes the sen- tence into separate words (you may want to use the strtok library function), inserts the words in a binary search tree and prints the inorder, preorder and postorder traversals of the tree. Use an OOP approach.

What will be an ideal response?


```
#include
#include
using namespace std;

#include "Tree.h"

int main()
{
Tree< string > stringTree;
char sentence[ 80 ];
char *tokenPtr;

cout << "Enter a sentence:\n";
cin.getline( sentence, 80 );

tokenPtr = strtok( sentence, " " );

// until the token is empty
while ( tokenPtr != 0 )
{
string *newString = new string( tokenPtr );
stringTree.insertNode( *newString );
tokenPtr = strtok( 0, " " );
} // end while

cout << "\nPreorder traversal\n";
stringTree.preOrderTraversal();

cout << "\nInorder traversal\n";
stringTree.inOrderTraversal();

cout << "\nPostorder traversal\n";
stringTree.postOrderTraversal();

cout << endl;
return 0; // indicates successful termination
} // end main
```
Enter a sentence:
ANSI/ISO C++ How to Program
Preorder traversal
ANSI/ISO C++ How to Program
Inorder traversal
ANSI/ISO C++ How Program to
Postorder traversal
Program to How C++ ANSI/ISO

Computer Science & Information Technology

You might also like to view...

WPF uses _________ graphics, which allows graphics to scale without losing quality.

a) bitmap b) vector c) raster-based d) jpeg

Computer Science & Information Technology

__________ is the use of a trusted third party to assure certain properties of a data exchange.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

Clicking the ________ tab in the Properties dialog box will change the appearance of the field name

Fill in the blank(s) with correct word

Computer Science & Information Technology

The data components of a class that belong to every instantiated object are the class's ____.

A. numeric variables B. string variables C. instance variables D. data variables

Computer Science & Information Technology