Hello Everyone,

I am creating a program for my class that will take a stack an within the stack call a 4 heap priority queue. What I am having trouble with is that my ListNode class within the "StackLList.h" cannot used in the "PQ.h". But, it works vice versa. The error is saying:

Error 1 error C2061: syntax error : identifier 'ListNode' c:\users\owner\documents\visual studio 2010\projects\4heap\4heap\pq.h 17 1 4Heap

PQ:

StackLList:

Main:

I am creating a program for my class that will take a stack an within the stack call a 4 heap priority queue. What I am having trouble with is that my ListNode class within the "StackLList.h" cannot used in the "PQ.h". But, it works vice versa. The error is saying:

Error 1 error C2061: syntax error : identifier 'ListNode' c:\users\owner\documents\v

PQ:

```
#ifndef PQ_H
#define PQ_H
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
#include"StackLList.h"
template<class Comparable>
class PQ
{
public:
PQ();
void insert(ListNode&);
void delete_max();
void swap(ListNode&, ListNode&);
void min(ListNode&, ListNode&);
private:
vector<ListNode> vector_PQ;
int size;
};
template<class Comparable>
PQ<Comparable>::PQ()
{
size = vector_PQ.size();
}
template<class Comparable>
void PQ<Comparable>::insert(ListNode &x)
{
if(vector_PQ.size() == 0)
{
vector_PQ.push_back(x);
return;
}
size++;
vector_PQ.push_back(x);
int child = size;
int parent = (child/4);
while(vector_PQ[parent] < vector_PQ[child])
{
swap(vector_PQ[parent], vector_PQ[child]);
child = parent;
parent = (child/4);
}
}
template<class Comparable>
void PQ<Comparable>::delete_max()
{
Comparable nextItem = vector_PQ[1];
swap(vector_PQ[1], vector_PQ[size]);
size--;
int parent = 0;
int child1 = (4*parent)+1;
int child2 = (4*parent)+2;
int child3 = (4*parent)+3;
int child4 = (4*parent)+4;
}
template<class Comparable>
void PQ<Comparable>::swap(ListNode& a, ListNode& b)
{
ListNode temp;
temp = a;
a = b;
b = temp;
}
#endif
```

StackLList:

```
#ifndef STACKLLIST_H
#define STACKLLIST_H
#include<iostream>
using namespace std;
#include"PQ.h"
template<class Data>
class ListNode
{
public:
ListNode(Data &nodeValue, int counter_value)
: value(nodeValue), next(NULL), counter(counter_value)
{}
ListNode *next;
Data value;
int counter;
};
template<class Data>
class StackLList
{
public:
StackLList();
~StackLList();
void push(Data&);
void pop(Data&);
bool isEmpty();
private:
ListNode<Data> *top;
PQ<Data> *queue;
};
template<class Data>
StackLList<Data>::StackLList()
{
top = NULL;
queue = new PQ<Data>;
}
template<class Data>
StackLList<Data>::~StackLList()
{
ListNode *node_ptr, *next_node;
node_ptr = top;
while(node_ptr != NULL)
{
next_node = node_ptr->next;
delete node_ptr;
node_ptr = next_node;
}
}
template<class Data>
void StackLList<Data>::push(Data& data)
{
static int timeStamp = 0;
timeStamp++;
ListNode<Data> *new_node = new ListNode<Data>(data,timeStamp);
if(isEmpty())
{
top = new_node;
new_node->next = NULL;
}
else
{
new_node->next = top;
top = new_node;
}
queue->insert(new_node);
}
template<class Data>
void StackLList<Data>::pop(Data& data)
{
ListNode *temp;
if(isEmpty())
cout<<"The Stack Is Empty"<<endl;
else
{
data = top->value;
temp = top->next;
delete top;
top = temp;
}
}
template<class Data>
bool StackLList<Data>::isEmpty()
{
bool flag;
if(top == NULL)
flag =true;
else
flag = false;
return flag;
}
#endif
```

Main:

```
#include<iostream>
#include<string>
using namespace std;
#include"StackLList.h"
int main()
{
cout<<"****************** 4-HEAP PROGRAM *******************"<<endl;
int number;
int answer = 1;
StackLList<int> *stack = new StackLList<int>;
do
{
cout<<"1) Push"<<endl;
cout<<"2) Pop"<<endl;
cout<<"3) Exit"<<endl;
cin>>answer;
if(answer == 1)
{
cout<<"Please Enter In Your Data"<<endl;
cin>>number;
stack->push(number);
}
else if(answer == 2)
cout<<"We Will Create A Delete Function"<<endl;
else
break;
}while(answer != 3);
system("PAUSE");
return 0;
}
```

```
template<class Comparable,class Data>
class PQ
{
public:
PQ();
void insert(ListNode<Data>&);
void delete_max();
void swap(ListNode<Data>&, ListNode<Data>&);
void min(ListNode<Data>&, ListNode<Data>&);
private:
vector<ListNode<Data> > vector_PQ;
int size;
};
```

```
template<class Data, class Comparable>
class StackLList
{
public:
StackLList();
~StackLList();
void push(Data&);
void pop(Data&);
bool isEmpty();
private:
ListNode<Data> *top;
PQ<Comparable,Data> *queue; // required now
};
```

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.