https://github.com/arnavbee/queues
https://github.com/arnavbee/queues
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/arnavbee/queues
- Owner: arnavbee
- Created: 2024-07-28T15:45:22.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-01T18:43:55.000Z (almost 2 years ago)
- Last Synced: 2025-06-11T02:05:51.618Z (about 1 year ago)
- Language: C++
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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();
}
};