#include "stdafx.h"
#include<iostream>
#include<conio.h>
using namespace std;
class linkedqueue
{
private:
struct node{
char data;
node *next;
};
node *rear, *front;
int count;
public:
linkedqueue()
{
count = 0;
front = rear = NULL;
}
bool isempty(){ return count == 0; }
void insert(char item)
{
node *p = new node;
p->data = item;
if (isempty())
{
rear = front = p;
rear->next = p;
p->next = NULL;
}
if (front == rear)
{
rear->next = p;
rear = p;
rear->next = NULL;
}
else
{
rear->next = p;
rear = p;
rear->next = NULL;
}
count++;
}
void display()
{
node *p = front;
while (p!=NULL)
{
cout << p->data << " ";
p = p->next;
}
}
char remove()
{
if (isempty())
{cout << "the Queue is Empty";
return NULL;
}
else
{
char item = front->data;
front = front->next;
return item;
}
count--;
}
};
void main()
{
linkedqueue q;
q.insert('a');
q.insert('b');
q.insert('c');
q.insert('d');
q.display();
cout << "\nDeleting one item:-\n";
q.remove();
q.display();
_getch();
}
0 التعليقات:
إرسال تعليق