cis22c/05-trees/Park.cpp
Iurii Tatishchev 01d2d7f2cf
8.14 Lab*: BT <--- BST ADT (Park)
- Modify the Park class from previous assignments.
- Rewrite the private insert as a recursive function.
- Write the buildBST() function (similar to buildList() in the doubly-linked list lab).
- Display the number of nodes in the tree as shown below:

- Display the tree in inorder, preorder or postorder
- Display the tree as an indented list
- Display the inner nodes of the BST (including its root), in alphabetical order by code

- Write the searchManager() function (similar to searchManager() in the doubly-linked list lab). It calls search BST in a loop.
- Search the BST (implement the recursive private search function).
2024-05-03 17:08:04 -07:00

81 lines
2.2 KiB
C++

// Implementation file for the Park class
// Written By: Iurii Tatishchev
// Reviewed By: Iurii Tatishchev
// IDE: CLion
#include <iostream>
#include <iomanip>
#include <string>
#include "Park.h"
using namespace std;
// **************************************************
// Constructor
// **************************************************
Park::Park() {
code = "";
state = "";
name = "";
description = "";
year = -1;
}
// **************************************************
// Overloaded Constructor
// **************************************************
Park::Park(string cd, string st, string nm, string dsc, int yr) {
code = cd;
state = st;
name = nm;
description = dsc;
year = yr;
}
// Friend Functions Definitions
// ***********************************************************
// hDisplay
// Displays code, state, and year data members of a Park object
// on one line (horizontal display)
// ***********************************************************
void hDisplay(const Park &item) {
cout << item.code << " ";
cout << item.state << " ";
cout << item.year << " ";
cout << endl;
}
// ***********************************************************
// vDisplay
// Displays name, description, state, and year of a Park object
// one per line (vertical display)
// ***********************************************************
void vDisplay(const Park &item) {
cout << " Name: " << item.name << endl;
cout << "Description: " << item.description << endl;
cout << " State: " << item.state << endl;
cout << " Year: " << item.year << endl;
}
// ***********************************************************
// iDisplay
// on one line, including the level number and
// ".." for each indentation level
// ***********************************************************
void iDisplay(const Park &item, int level) {
for (int i = 1; i < level; i++)
cout << "..";
cout << level << "). " << item.code << endl;
}
// ***********************************************************
// kDisplay
// Displays the key: code of a Park object
// on one line (key display)
// ***********************************************************
void kDisplay(const Park &park) {
cout << park.code << "\n";
}