#include #include
int size; struct stack { Int a[max]; Int top; }; void stk(struct stack *st) { st->top = –1; } void push(struct stack *st,int num) { If(st->top == size–1) { printf(“\n over flow\n”); return; } st->top++; st->a[st->top]=num; } Int pop(stuct stack *st) { Int num; If(st->top==-1) { printf(“stack is under folw\n”); return NULL; } num=st->a[st->top]; st->top—; return num; } void display(struct stack *st) { Int i; for(i=st->top;i>=0;i—) printf(“\n %d\t”,st->a[i]); } void main() { Int d,i,n; struct stack *ptr; do { printf(“\n menu items\n1.push \t 2.pop\t3.display\t 4.exit\n”); printf(“enter your choice:”); scanf(“%d”,&i); switch(i) { case 1: printf(“enter an element:”); scanf(“%d”,&n); push(&ptr,n); break; case 2: d=pop(&ptr); printf(“\n deleted item %d”,d); break; case 3: printf(“elements of the stack are \n”); display(&ptr); break; case 4: exit (0); default: printf(“invalid choice”); } } getch(); }
|
No feedbacks found. Be the first to respond and make money from revenue sharing program.
|