Last active
November 10, 2018 22:19
-
-
Save ahmedalkabir/8f4277e48f9f3e812d56c2d57fa30839 to your computer and use it in GitHub Desktop.
STACK implemetation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
int STACK[100], s_of_element, top; | |
void push(void){ | |
int temp; | |
if(top >= s_of_element-1){ | |
cout << "STACK IS FULL" << endl; | |
}else{ | |
cout << "\nEnter a value to be pushed: "; | |
cin >> temp; | |
STACK[++top] = temp; | |
} | |
} | |
int pop(void) { | |
if(top<=-1){ | |
cout << "STACK is empty" << endl; | |
return 0; | |
}else{ | |
return STACK[top--]; | |
} | |
} | |
void show(void){ | |
if(top >= 0){ | |
cout << "The elements of STACK is ...... " << endl; | |
for(int i=top; i>=0; i--) | |
cout << "The Element : " << STACK[i] << endl; | |
cout << "\n\nPress Next Choice " << endl; | |
}else{ | |
cout << "The STACK is empty " << endl; | |
} | |
} | |
int main(void){ | |
int choice; | |
top = -1; | |
cout << " Simple Stack Implementation using Array 0" << endl; | |
cout << "Enter the size of STACK MAX=100: "; | |
cin >> s_of_element; | |
cout << " 1.PUSH\n 2.POP\n 3.SHOW\n 4.EXIT" << endl; | |
do{ | |
cout << "Enter YOUR Choice :"; | |
cin >> choice; | |
switch(choice){ | |
case 1: | |
push(); | |
break; | |
case 2: | |
cout << "The popped element is " << pop() << endl;; | |
break; | |
case 3: | |
show(); | |
break; | |
case 4: | |
cout << "\n EXITING....." << endl; | |
break; | |
default: | |
cout << "\n\t Invaild option " << endl; | |
break; | |
} | |
}while(choice != 4); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment