An open API service indexing awesome lists of open source software.

https://github.com/arnavbee/queues


https://github.com/arnavbee/queues

Last synced: 12 months ago
JSON representation

Awesome Lists containing this project

README

          

# Queue

Queue is the type of data structure used to store data in the form of FIFO(First In First Out)

It has the same operations as stacks but the first element gets picked out first in the pop operation.

## Implementation Of Queue using Array

class Queue {
public:
int size;
int *arr;
int start;
int end;

int currSize;

Queue(int s){
this -> size = s;
arr = new int[size];
start = -1;
end = -1;
currSize = 0;
}

void push(int element){

if(currSize == size) {
cout<<"Stack Overflow"<
#include

class MyStack {
queue qt;
public:


void push(int x) {

int s = qt.size();


qt.push(x);

for(int i = 0; i < s; ++i){
qt.push(qt.front());
qt.pop();

}



}

int pop() {

if (qt.empty()) {
return -1;
}

int topElement = qt.front();
qt.pop();

return topElement;


}

int top() {

if (qt.empty()) {

return -1;
}

int topElement =qt.front();
return topElement;

}

bool empty() {
return qt.empty();
}

};