Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define Max 5
- void push();
- void pop();
- void display();
- int top=-1;
- char stack[Max];
- int main(){
- int choice;
- while (1){
- printf("1.Push\n");
- printf("2.Pop\n");
- printf("3.Display\n");
- printf("Enter your choice\n");
- scanf("%d",&choice);
- switch (choice){
- case 1: push();
- break;
- case 2: pop();
- break;
- case 3: display();
- break;
- }
- }
- }
- void push(){
- char ltr;
- if(top==(Max-1)){
- printf ("Over maxsize\n");
- }
- else{
- printf("Enter the element for push\n");
- scanf("%s", <r);
- top=top+1;
- stack[top]=ltr;
- }
- }
- void pop(){
- char ltr;
- if (top==-1){
- printf ("Stack empty\n");
- }
- else{
- ltr=stack[top];
- printf("poped is=%c\n",ltr);
- top=top-1;
- }
- }
- void display(){
- if(top==-1){
- printf("empty\n");
- }
- else{
- printf("stack is\n");
- for(int i=top;i>=0;i--){
- printf("%c\n",stack[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement