Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Input & Output :->
- 1 for Push
- 2 for Pop
- Any key to just print the stack
- 1
- Enter the element 5
- 1 - for repeat and any key to exit 1
- 1 for Push
- 2 for Pop
- Any key to just print the stack
- 3
- 5
- 1 - for repeat and any key to exit -1
- */
- #include<stdio.h>
- #include<conio.h>
- #define Stack_Size 50
- int stack[Stack_Size],top;
- int Is_empty(){
- if(top==-1)return 1;
- else return 0;
- }
- int Is_full(){
- if(top==Stack_Size-1) return 1;
- else return 0;
- }
- void Push(int element){
- stack[++top]=element;
- }
- void Pop(){
- stack[top--]=0;
- }
- void Print(){
- if(Is_empty()){
- printf("There is no element to print");
- return;
- }
- else{
- for(int i=0 ; i<=top ; i++){
- printf("%d ",stack[i]);
- }
- }
- }
- int main()
- {
- top=-1;
- int key,choice,element;
- while(1){
- printf("\n1 for Push \n2 for Pop\nAny key to just print the stack\n");
- scanf("%d",&choice);
- if(choice==1){
- printf("\nEnter the element ");
- scanf("%d",&element);
- Push(element);
- }
- else if(choice==2){
- Pop();
- }
- else Print();
- printf("\n1 - for repeat and any key to exit ");
- scanf("%d",&key);
- if(key!=1)break;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment