hw05sol -...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: #include <stack> #include <map> #include <string> #include <iostream> using namespace std; u class BTnode; class BTnode { public: BTnode(char e, BTnode *l=NULL, BTnode *r=NULL):element(e),left(l),right(r){}; char element; BTnode *left, *right; }; } bool eval(BTnode *t, map<char,bool>& vars) { if (t==NULL) { cout << "Unexpected empty tree" << endl; return false; } switch (t->element) { case '&': return (eval(t->left, vars) && eval(t->right, vars)); case '|': return (eval(t->left, vars) || eval(t->right, vars)); case '~': return !(eval(t->right,vars)); case 'T': return(true); case 'F': return(false); default: return vars[t->element]; // assumes every identifier in a leaf was included in vars } } bool eval_driver(BTnode *root, map<char,bool>& vars) { //driver function for eval //prompts users to instantiate the variables, then calls eval map<char,bool>::iterator i; char val; for(i= vars.begin(); i!= vars.end(); ) { cout<<"Enter value for " << i->first <<" (T or F)" << endl; cin >> val; if ((val == 'T')||(val=='t')){i->second=true; ++i;} else if ((val == 'F')||(val=='f')) {i->second=false; ++i;} else cout << "Try again" <<endl;...
View Full Document

This note was uploaded on 02/02/2011 for the course CS 2134 taught by Professor Hellerstein during the Fall '07 term at NYU Poly.

Page1 / 5

hw05sol -...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online