1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
// FILE: assignment4Demo.cxx
// A demo program for programming assignment 4
// Written by Shivakant Mishra
// Last Update: April 23, 2010
#include <iostream>
#include <cassert> // Provides assert
#include <cstdlib> // Provides NULL and size_t
#include <stack> // STL stack
#include <queue> // STL queue
#include "assignment4.h"
//#include "bintree.h"
using namespace std;
using namespace assignment4;
//using namespace main_savitch_10;
template <class Item>
boolean insert_equivalent (stack<Item> *s, queue<Item> *q);
void print_value(int i)
{
cout << i;
}
void add_five(int& i)
{
i += 5;
}
int main( )
{
char str1[20] = "({({}{()})()})";
char str2[20] = "({({}{()})()}";
char str3[20] = "";
char str4[20] = "{(({))}}";
if (balanced(str1)) cout << "str1 is balanced" << endl;
else cout << "str1 is not balanced" << endl;
if (balanced(str2)) cout << "str2 is balanced" << endl;
else cout << "str2 is not balanced" << endl;
if (balanced(str3)) cout << "str3 is balanced" << endl;
else cout << "str3 is not balanced" << endl;
if (balanced(str4)) cout << "str4 is balanced" << endl;
else cout << "str4 is not balanced" << endl;
stack<int> *s = new stack<int>;
queue<int> *q = new queue<int>;
queue<int> *nq = new queue<int>;
for (int i = 0; i<10; i++) {
s->push(i);
q->push(i);
nq->push(9-i);
}
if (insert_equivalent(s, q))
cout << "s and q are insert equivalent" << endl;
else cout << "s and q are not insert equivalent" << endl;
if (insert_equivalent(s, nq))
cout << "s and nq are insert equivalent" << endl;
else cout << "s and nq are not insert equivalent" << endl;
binary_tree_node<int> n1(10), m1(10), l1(10);
binary_tree_node<int> n2(20), m2(20), l2(20);
binary_tree_node<int> n3(30), m3(30);
binary_tree_node<int> n4(50, &n2, &n3), m4(50, &m2, &m3);
binary_tree_node<int> n5(40, &n1, &n4), m5(40, &m1, &m4);
binary_tree_node<int> l4(50, &l2), l5(40, &l1, &l4);
if (equal_tree(&n5, &m5)) cout << "m and n are equal" << endl;
else cout << "m and n are not equal" << endl;
if (equal_tree(&n5, &l5)) cout << "l and n are equal" << endl;
else cout << "l and n are not equal" << endl;
if (equal_tree(&m5, &l5)) cout << "l and m are equal" << endl;
else cout << "l and m are not equal" << endl;
//
// cout << "Data fields of tree n in post order are " ;
// postorder_process(print_value, &n5);
// cout << endl;
//
// postorder_process(add_five, &m5);
// cout << "Data fields of tree m in post order are " ;
// postorder_process(print_value, &m5);
// cout << endl;
}
|