Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct data
- {
- int a;
- char c;
- struct data *next;
- } data;
- data *head=NULL;
- void push(int x,char y)
- {
- data *n=(data*)malloc(sizeof(data));
- n->a=x;
- n->c=y;
- n->next=NULL;
- if(head==NULL)
- {
- head=n;
- return;
- }
- n->next=head;
- head=n;
- return;
- }
- int pop()
- {
- if(head==NULL)
- {
- return printf(" Nothing to");
- }
- data *del=head;
- int m=head->a;
- return printf(" Popped :%d ",m);
- }
- char popc()
- {
- if(head==NULL)
- {
- return printf(" POP\n");
- }
- data *del=head;
- char p=del->c;
- head=head->next;
- free(del);
- return printf("%c \n",p);
- }
- int top()
- {
- if(head==NULL)
- {
- return printf(" Top is Empty \n");
- }
- return printf(" Top: %d %c \n",head->a, head->c);
- }
- void reset()
- {
- head=NULL;
- printf(" Reseted\n");
- return;
- }
- int print()
- {
- data *temp=head;
- if(head==NULL)
- {
- printf(" Empty");
- }
- while(temp!=NULL)
- {
- printf(" %d %c",temp->a, temp->c);
- temp=temp->next;
- }
- printf("\n");
- }
- int main()
- {
- int n,aa;
- char cc;
- while(1)
- {
- //printf("\n%d %d %d \n",head->a, head->next->a,head->next->next->a);
- printf("\n1.PUSH\n");
- printf("2.POP\n");
- printf("3.TOP\n");
- printf("4.PRINT\n");
- printf("9.RESET\n");
- printf("0.BREAK\n");
- printf(" Command: ");
- scanf("%d",&n);
- printf("\n");
- if(n==1)
- {
- printf("Integer & Character: ");
- scanf("%d %c",&aa,&cc);
- push(aa,cc);
- }
- if(n==2)
- {
- pop();
- popc();
- }
- if(n==3)
- {
- top();
- }
- if(n==4)
- {
- print();
- }
- if(n==9)
- {
- reset();
- }
- if(n==0)
- {
- printf(" Prgrm Clossed\n");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement