Stacks.cpp

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> using namespace std; //implemenation of stacks using arrays. #define Max 20 class Stack{ int stack[Max]; int top = 0; public: void push(int value) { if(top == Max-1) { cout<<"Stack Overflow"<<"\n"; return; } top++; stack[top] = value; } int pop() { if(top == 0) { cout<<"Underflow"<<"\n"; return -1; } int value = stack[top]; top--; return value; } int peek() { return stack[top]; } }; int main() { Stack s1; s1.push(5); s1.push(6); s1.push(7); cout<<s1.pop()<<"\n"; cout<<s1.peek()<<"\n"; return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines