Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Added Stack Operations based on Arrays using the programming language C++ #256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
Loading
from
Open
Changes from 1 commit
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
Next Next commit
Added Stack operations Based on arrays.cpp
  • Loading branch information
Zanark committed Dec 25, 2017
commit 87d741293b0970e615cb66162c7a39aba63c9599
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@

// All Operations on Stacks based on ARRAYS
//--------------------------------------------------------------------------------------

#include<iostream>
#include<conio.h>
#include<stdlib.h>

using namespace std;

class stack
{
int stk[101];
int top;

public:

stack() // Initialising an Empty Stack
{
top=-1;
}


void push(int x) // To Insert Elements onto the Stack
{
if(top > 100) // To Check if the Stack is already FULL
{
cout <<"\n\n !!!! Stack over flow !!!!";
return;
}
stk[++top]=x;
cout <<"\n The inserted element is : \t" <<x; // Inserting a NEW element and making it the NEW Top
}


void pop() // To Delete an element from the Stack
{
if(top <0) // To check if the Stack is already EMPTY
{
cout <<"\n\n !!!! Stack under flow !!!!";
return;
}
cout <<"deleted" <<stk[top--]; // Deleting an element and making the PREVIOUS element the NEW TOP
}


void display() // To Display the Stack
{
if(top<0)
{
cout <<"\n\n Stack is empty :(";
return;
}
for(int i=top;i>=0;i--)
{
if (i == top)
cout<<"\n Top --> ";
cout <<stk[i] <<" ";
}
}
};

main()
{
int ch;
int ele;
stack st;
while(1)
{
cout << "\n What do you want to do?"
<< "\n\n 1. Push an element onto the Stack"
<< "\n\n 2. Pop an element from the Stack"
<< "\n\n 3. Display the Stack"
<< "\n\n 4. EXIT the program"
<< "\n\n\n\n Please Enter your choice\n";
cin >> ch;
switch (ch)
{
case 1:
cout << "\n Enter the element \t:\t";
cin >> ele;
st.push(ele);
break;
case 2:
st.pop();
break;
case 3:
st.display();
break;
case 4:
exit(0);
}
}
return (0);
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.