Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions queue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include<bits/stdc++.h>
#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!!!"<<endl;
}
else {
cout<<"Inserting "<<x<<" into the queue..."<<endl;
size++;
rear = (rear+1)%capacity;
arr[rear]=x;
}
}

//function to remove element from queue
int Queue::dequeue() {
if(isEmpty()) {
cout<<"Queue Empty!!!"<<endl;
}
else {
cout<<"Removing "<<arr[front]<<" from the queue..."<<endl;
int temp = arr[front];
size--;
front = (front+1)%capacity;
return temp;
}
}


//function to return size of queue
int Queue::qsize() {
return size;
}

//function to check if queue is empty or not
bool Queue::isEmpty() {
return(size==0);
}

//function to check if queue is full or not
bool Queue::isFull() {
return(size==capacity);
}

int main() {

return 0;
}

77 changes: 77 additions & 0 deletions stack.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include<bits/stdc++.h>
#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!!!"<<endl;
}
else {
cout<<"Inserting "<<x<<" into the stack..."<<endl;
top++;
arr[top] = x;
}
}

//function to pop element from stack
int Stack::pop() {
if(isEmpty()) {
cout<<"Stack Empty!!!"<<endl;
}
else {
cout<<"Removing "<<arr[top]<<" from the stack..."<<endl;
return arr[top];
top--;
}
}

//function to return stack size
int Stack::size() {
return top+1;
}

//function to check whether stack is empty
bool Stack::isEmpty() {
return top==-1;
}

//function to check whether stack has reached maximum capacity
bool Stack::isFull() {
return top == capacity-1;
}

int main() {

return 0;
}