What's wrong with this function definition? (Stacks/queues)

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
#ifndef ASSIGNMENT4_H_
#define ASSIGNMENT4_H_

namespace assignment4
{ 
	#include <vector>
	#include <stack>
	#include <queue>
	
	typedef bool boolean;
	template <class Item>
	class binary_tree_node
	{
		public:
			binary_tree_node(const Item& init_data = Item( ),
							 binary_tree_node *init_left = NULL,
							 binary_tree_node *init_right = NULL);
			~binary_tree_node( );
			Item& data( );
			binary_tree_node*& left( );
			binary_tree_node*& right( );
			void set_data(const Item& new_data);
			void set_left(binary_tree_node *new_left);
			void set_right(binary_tree_node *new_right);
			bool is_leaf( ) const;
		private:
			Item data_field;
			binary_tree_node *left_field;
			binary_tree_node *right_field;
	};
	
	boolean balanced(char* p);
	
	template <class Item>
	boolean insert_equivalent (stack<Item> *s, queue<Item> *q);

	template <class Item>
	boolean equal_tree (const binary_tree_node<Item> *t1, const binary_tree_node<Item> *t2);
    
    template <class Process, class BTNode>
    void postorder_process(Process f, BTNode* nodeptr);
}

#endif /*ASSIGNMENT4_H_*/ 


It's on line 36...I'm getting six errors. I can't tell what's wrong.

error: ‘q’ was not declared in this scope
error: ‘queue’ was not declared in this scope
error: ‘s’ was not declared in this scope
error: ‘stack’ was not declared in this scope
error: expected primary-expression before ‘>’ token
error: template declaration of ‘assignment4::boolean assignment4::insert_equivalent’


EDIT: It looks like it might also have to do with my main.cpp file? I'm not entirely sure, either. It's not liking it when I call insert_equivalent:

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;
}
Last edited on
stack and queue are all declared in the std namespace.

You'll want to move your #includes outside your namespace also.
Topic archived. No new replies allowed.