0
#include <iostream>
1.
include "linkedlist.h"
using namespace std;
class queue{
private:
linkedlist list;
node *head,*tail;
int count;
public:
queue();// constructor
void enqueue (int value);
int dequeue();
int getfront();
void display();
};
queue::queue()
{
head= null;
tail= null;
count=0;
}
void queue::enqueue(int data) {
count++;
node *n = new node;
n->data = data;
n->next = null;
if(head==null)
{
n->next=head;
head=n;
}else {
if(tail=null){
n->next=tail;
tail=n;
}
while(tail!=null) {
tail = tail->next;
}
}
}
int queue::dequeue() {
count--;
if(head=null)
cout<<"queue is empty"<<endl;
node* cur;
cur = head;
head = head->next;
return cur->data;
}
void queue::display() {
node *cur = head;
cout<<"[";
while(cur != null)
{
cout << cur->data << " ";
cur = cur->next;
}
cout<<"]";
cout << endl;
}
int queue::getfront() {
if(count==0)
{
cerr<<"queue is empty!" <<endl;
exit(1);
}
else
{
return head->data;
}
}