why the given code in which i have implemented queue using linked list is not giving the correct output?
#include
using namespace std;
//implementation of queue using linked list
struct node{
int data;
node *next;
public:
node(int data){
this->data=data;
next=NULL;
}
};
struct queue{
private:
node *head;
node * front;
node *rear;
public:
queue(){
head=NULL;
front=head;
rear=head;
}
bool empty(){
return head==NULL;
}
void enqueue(int data){
node *n=new node(data);
if(empty()){
head=n;
rear=head;
front=head;
cout<data<<endl;
return;
}
rear->next=n;
rear=rear->next;
cout<<rear->data<<endl;
}
void dequeue(){
if(!empty()){
cout<data<<endl;
node *temp=front;
head=head->next;
front=front->next;
delete temp;
//cout<<front->data<<endl;
}}
int getfront(){
return front->data;
}
void print(){
node *temp=head;
while(head!=NULL){
cout<<head->data<<"->";
head=head->next;
}}
};
int main(){
queue q;
for(int i=48;i<56;i++){
q.enqueue(i);
}
q.print();
while(!q.empty()){
cout<<q.getfront()<<endl;
q.dequeue();
}
return 0;
}