/////////////////////////////////////////////////////////////////////////// // Nodes.cpp - demonstrate how to define a template node class // // ver 1.1 // // Language: Visual C++, 2008 // // Platform: Dell Precision T7400, Vista Ultimate, SP1 // // Application: CSE382 - Algorithms and Data Structures Demo, Fall 2008 // // Author: Jim Fawcett, Syracuse University, CST 4-187, // // (315) 443-3948, jfawcett@twcny.rr.com // /////////////////////////////////////////////////////////////////////////// #include #include #include "Nodes.h" using namespace AbstractDataTypes; #ifdef TEST_NODES void WalkTree(MNode* pMNode) { std::cout << "\n " << pMNode->value(); MNode* pTemp; while(pTemp = pMNode->nextUnmarkedChild()) { pTemp->isMarked() = true; WalkTree(pTemp); } } void main() { std::cout << "\n MNode class demonstration"; std::cout << "\n ==============================\n"; MNode root("root"); MNode child1("child1"); MNode child2("child2"); MNode grandchild11("grandchild11"); MNode grandchild21("grandchild21"); MNode grandchild22("grandchild22"); MNode greatgrandchild211("greatgrandchild211"); MNode child3("child3"); child1.add(&grandchild11); grandchild21.add(&greatgrandchild211); child2.add(&grandchild21); child2.add(&grandchild22); root.add(&child1); root.add(&child2); root.add(&child3); WalkTree(&root); std::cout << "\n\n removing first child"; root.remove(&child1); std::cout << "\n unmarking all nodes"; root.isMarked() = false; child1.isMarked() = false; grandchild11.isMarked() = false; child2.isMarked() = false; grandchild21.isMarked() = false; grandchild22.isMarked() = false; greatgrandchild211.isMarked() = false; child3.isMarked() = false; WalkTree(&root); std::cout << "\n\n"; } #endif