Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This checkpoint submission is worth 20% of the PROGRAM 3 score. It uses the tests from Page 1 (except insert i) and Page 1b. Use

This checkpoint submission is worth 20% of the PROGRAM 3 score. It uses the tests from Page 1 (except insert i) and Page 1b.

Use the main.cpp file provided here: https://ide.c9.io/krism/cs14 They are now also in a google drive: 23Tree Files

You will need to reverse engineer how to do a preorder and postorder traversal in a 2-3 tree. Given the input:

Die Hard, Terminator, Kill Bill Volume 1, Pirates of the Caribbean, The Lord of the Rings, Star Wars, Gladiator, Aliens, Matrix 

The output should be:

Preorder: Kill Bill Volume 1, Die Hard, Aliens, Gladiator, Pirates of the Caribbean, Matrix, Terminator, Star Wars, The Lord of the Rings Inorder: Aliens, Die Hard, Gladiator, Kill Bill Volume 1, Matrix, Pirates of the Caribbean, Star Wars, Terminator, The Lord of the Rings Postorder: Aliens, Gladiator, Die Hard, Matrix, Star Wars, Pirates of the Caribbean, The Lord of the Rings, Terminator, Kill Bill Volume 1 

#include "Tree.h" #include

using namespace std;

void printOrders(Tree *tree) { cout << "Preorder = "; tree->preOrder( ); cout << "Inorder = "; tree->inOrder( ); cout << "Postorder = "; tree->postOrder( ); }

int menu() { int choice = 0; cout << endl << "Enter menu choice: "; cout << endl; cout << "1. Insert" << endl << "2. Remove" << endl << "3. Print" << endl << "4. Search" << endl << "5. Quit" << endl; cin >> choice; // fix buffer just in case non-numeric choice entered // also gets rid of newline character cin.clear(); cin.ignore(256, ' '); return choice; }

int main( ) {

Tree tree;

int choice = menu();

string entry; while (choice != 5) { if (choice == 1) { cout << "Enter movie title to insert: "; getline(cin, entry); cout << endl; tree.insert(entry); } else if (choice == 2) { cout << "Enter movie title to remove: "; getline(cin, entry); cout << endl; tree.remove(entry); } else if (choice == 3) { printOrders(&tree); } else if (choice == 4) { cout << "Enter movie title to search for: "; getline(cin, entry); cout << endl; if (tree.search(entry)) { cout << "Found" << endl; } else { cout << "Not Found" << endl; } }

//fix buffer just in case non-numeric choice entered choice = menu(); } return 0; }

node.cpp

#ifndef __NODE_H #define __NODE_H

#include

using namespace std;

class Node {

friend class Tree;

private: string small; string large;

Node *left; Node *middle; Node *right; Node *parent;

// Add additional functions/variables here. Remember, you may not add any // Node * or string variables.

};

#endif

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

Database Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

More Books

Students also viewed these Databases questions