Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include<Conio.h>
- #define max 10
- struct stack
- {
- int top;
- int item[max];
- }s;
- void push();
- void pop();
- void display();
- void main()
- {
- system("cls");
- s.top=-1;
- int choice;
- while (1)
- {
- printf("Enter your choice");
- printf("\n1.Push\n 2. Pop\n 3.Display \n4.Exit\n");
- scanf("%d",&choice);
- switch (choice)
- {
- case 1:push();
- break;
- case 2:pop();
- break;
- case 3:display();
- break;
- case 4:
- exit(0);
- default: printf("Enter number in range: \n");
- }
- }
- }
- void push()
- {
- int val;
- if (s.top==max-1)
- printf("Overflow:");
- else
- {
- printf("Enter the element you want to push: \n");
- scanf("%d",&val) ;
- s.top=s.top+1;
- s.item[s.top]=val;
- }
- }
- void pop()
- {
- if (s.top==-1)
- {
- printf("Empty stack");
- }
- else
- {
- printf("Deleted stack is %d\n",s.item[s.top]);
- s.top=s.top-1;
- }
- }
- void display()
- {
- system("cls");
- int i;
- if (s.top==-1)
- {
- printf("Empty\n");
- }
- else
- {
- for (i=s.top;i>=0;--i)
- {
- printf("Stack:\%d \n",s.item[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement