Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Stack Program
- // Date : 08.04.19
- #include<iostream>
- #include<cstdlib>
- #define max_size 20
- using namespace std;
- class stack_class{
- int stack_array[max_size];
- int top;
- void insert_stack();
- void delete_stack();
- void display();
- public:
- stack_class() { top = 0; }
- void control_function();
- };
- void stack_class::display(){
- if(top == 0){
- cout << "The Stack is Underflow nothing to display.\n";
- return;
- }
- else{
- cout << "The element in the Stack are: \n";
- for(int i = top-1; i > -1; i--){
- cout << stack_array[i] << ' ';
- }
- cout << endl << endl;
- }
- }
- void stack_class::delete_stack(){
- if(top == 0){
- cout << "The Stack is Underflow.\n";
- return;
- }
- else{
- cout << "The element " << stack_array[--top]
- << " is deleted\n";
- }
- }
- void stack_class::insert_stack(){
- if(top == max_size){
- cout << "The Stack is Overflow.\n";
- return;
- }
- else{
- cout << "Enter Element to display: ";
- cin >> stack_array[top++];
- }
- }
- void stack_class::control_function(){
- while(1){
- cout << "* * * * * Welcome to Stack program * * * * *\n"
- << "Press 1 to Insert.\n"
- << "Press 2 to Delete.\n"
- << "Press 3 to Display Stack.\n"
- << "Press 4 to Exit.\n"
- << "\nEnter your choice: ";
- int choice; cin >> choice;
- system("cls");
- if(choice == 1) insert_stack();
- else if(choice == 2) delete_stack();
- else if(choice == 3) display();
- else if(choice == 4) break;
- else cout << "Wrong Choice.\n\n";
- }
- }
- int main(){
- stack_class ob1;
- ob1.control_function();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement