Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- typedef struct data
- {
- int a;
- char c[100];
- struct data *next;
- } data;
- data *head=NULL;
- void push()
- {
- data *new_node=(data*)malloc(sizeof(data));
- printf(" Integer: ");
- scanf("%d",&new_node->a);
- printf("\n Character: ");
- scanf(" %[^\n]s",new_node->c);
- new_node->next=NULL;
- if(head==NULL)
- {
- head=new_node;
- return;
- }
- new_node->next=head;
- head=new_node;
- return;
- }
- //data *copy=NULL;
- void pop()
- {
- if(head==NULL)
- {
- printf(" Nothing To POP Bro\n");
- return;
- }
- // copy->a=head->a;
- //
- // strcpy(copy->c,head->c);
- data *del=head;
- printf(" POPPED: %d %s\n",head->a,head->c);
- head=head->next;
- free(del);
- return;
- }
- void top()
- {
- if(head==NULL)
- {
- printf(" Top is Empty \n");
- return ;
- }
- printf(" Top: %d %s \n",head->a, head->c);
- return;
- }
- void reset()
- {
- head=NULL;
- printf(" Reseted\n");
- return;
- }
- void print()
- {
- data *temp=head;
- printf(" Result: ");
- if(head==NULL)
- {
- printf("Stack Empty");
- }
- while(temp!=NULL)
- {
- printf("%d %s",temp->a, temp->c);
- temp=temp->next;
- }
- printf("\n");
- }
- int main()
- {
- int n;
- while(1)
- {
- 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)
- {
- push();
- }
- if(n==2)
- {
- pop();
- }
- 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