Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
stack and queue
#include<iostream> #define max 4 using namespace std; int stack_arr[max]; int top= -1; void push(int data) { if(top == max-1) { printf("stack overflow"); return; } top=top+1; stack_arr[top]= data; } void pop() { if(top==-1) { cout<<"\nStack underflow\n"; return; } else { top--; } } void tope() { cout<<"\n\t"<<stack_arr[top]<<"\n"; } int queue[max]; int rear=0; int front=0; void fronte() { cout<<"\nQueue front "<<queue[front]<<"\n"; } void enqueue(int n) { if (max==rear) { printf("\nQueue is full\n"); return; } else { queue[rear] = n; rear++; } return; } void dequeue() { if (front == rear) { printf("\nQueue is empty\n"); return; } else { for (int i = 0; i < rear - 1; i++) { queue[i] = queue[i + 1]; } rear--; } return; } void display() { if(front==rear) cout<<"\nqueue is empty\n"; else { for(int i=front;i<rear;i++) cout<<queue[i]; } } int main() { cout<<"\n--queue Implementation--\n"; enqueue(9); enqueue(6); enqueue(8); enqueue(4); dequeue(); display(); fronte(); cout<<"\n"; cout<<"\n--stack Implementation--\n"; push(7); push(11); push(20); tope(); pop(); tope(); }
run
|
edit
|
history
|
help
0
const test
MyStringv2
MACRO
Intersected Rectangles
SD
a
Variadic Functor Example
Hello World
replace_copy-30-Seconds-of-C++
Fractional Knapsack