If Any Required Program Please Ask In Comment I Will Help You(any Program in JAVA or C++) . . THANKS FOR VISITING MY BLOG!

If U LIKE MY PROFILE RAISE YOUR HAND IF U NOT RAISE UR STANDARD. Powered by Blogger.

Sunday, October 21, 2018

PROGRAM FOR DeQUEUE.



#include <iostream>
#include <stdlib.h>
#include <conio.h>

using namespace std;

template <class Type>

class DeQueue
{
private:
Type *Queue;
int Size, Front, Rear, Count;

public:
DeQueue(int Siz)
{
Size = Siz;
Queue = new Type[Size];

Front = Count = -1;
Rear = Size - 1;
}

void EnQueue_Beg(Type Ch)
{
if (IsFull())
{
cout << "\nSTACK OVERFLOWED...!!!\n" << endl;
exit(1);
}

Count++;
Queue[++Front] = Ch;
}

void EnQueue_End(Type Ch)
{
if (IsFull())
{
cout << "\nSTACK OVERFLOWED...!!!\n" << endl;
exit(1);
}

Count++;
Queue[Rear--] = Ch;
}

Type dQueue_Beg()
{
if (IsEmpty())
{
cout << "\nSTACK UNDERFLOWED...!!!\n" << endl;
exit(1);
}

Count--;
return Queue[Front--];
}

Type dQueue_End()
{
if (IsEmpty())
{
cout << "\nSTACK UNDERFLOWED...!!!\n" << endl;
exit(1);
}

Count--;
return Queue[++Rear];
}

inline bool IsFull()
{
return Count == Size - 1;
}

inline bool IsEmpty()
{
return Count == -1;
}
};

int main()
{
DeQueue<int> Obj(10);

Obj.EnQueue_Beg(1);
Obj.EnQueue_End(99);

cout << "Element From Beginning: " << Obj.dQueue_Beg() << endl;
cout << "Element From End: " << Obj.dQueue_End() << endl;

getch();
return 0;
}

0 comments:

Post a Comment