diff --git a/queue.cpp b/queue.cpp new file mode 100644 index 0000000..4cd026f --- /dev/null +++ b/queue.cpp @@ -0,0 +1,83 @@ +#include +#define SIZE 100 //default stack size + + +using namespace std; + +//Queue implementation + +class Queue { + int *arr; //pointer to queue + int front,rear,size,capacity; +public: + Queue(int s = SIZE); + ~Queue(); + void enqueue(int x); + int dequeue(); + int qsize(); + bool isEmpty(); + bool isFull(); +}; + +//Constructor for class Queue initialized with size of queue +Queue::Queue(int s) { + arr = new int[s]; + capacity = s; + front = 0; + rear = -1; + size = 0; +} + +//destructor for class Queue +Queue::~Queue() { + delete arr; +} + +//function to push element into queue +void Queue::enqueue(int x) { + if(isFull()) { + cout<<"Queue Overflow!!!"< +#define SIZE 100 //default stack size + +using namespace std; + +//Stack Implementation + +class Stack { + int *arr; //pointer to stack + int top; //index of topmost element in stack + int capacity; //maximum size of stack + +public: + Stack(int size = SIZE); + ~Stack(); + void push(int); + int pop(); + int size(); + bool isEmpty(); + bool isFull(); +}; + +//Constructor for class stack initialized with size of stack +Stack::Stack(int size) { + arr = new int[size]; + capacity = size; + top = -1; +} + +//destructor for class stack +Stack::~Stack() { + delete arr; +} + +//function to push element into stack +void Stack::push(int x) { + if(isFull()) { + cout<<"Stack Overflow!!!"<