Reputation: 55
I'm trying to create a Queue program, but I keep getting errors that "front" and "rear" are not declared in this scope. Can anyone tell me what I'm doing wrong? Here is my code. I've comparing it to other code I've written, and I've declared them exactly the same way.
#include <iostream>
using namespace std;
class node{
public:
int data;
node *next;
node();
};
class que{
public:
node *front;
node *rear;
void enq(int a);
void deq();
void pq();
que();
};
que::que(){
front = NULL;
rear = NULL;
}
node::node(){
data = 0;
next = NULL;
}
void enq(int a){
node *temp;
temp = new node;
temp->data = a;
if(front == NULL && rear == NULL){
front = rear = temp;
}
else{
rear->next = temp;
rear = temp;
}
}
void deq(){
node *temp;
temp = front;
if(front == NULL)
return;
if(temp == rear)
front = rear = NULL;
else{
temp = temp->next;
}
delete temp;
}
void pq(){
node *curs;
curs = front;
if(front == NULL)
return;
while(1){
cout << curs->data;
if(curs->next == NULL)
break;
else
curs=curs->next;
}
}
int main(){
que *Q = new que;
return 0;
}
Upvotes: 1
Views: 690
Reputation: 5083
In your code, you start defining functions like:
void pq(){
But that's not part of the class, you have to say:
void deq::pq(){
Upvotes: 3