Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct x
- {
- char b[50];
- struct x *ptr;
- } x;
- x *a,*head=NULL,*temp,*temp1;
- void print()
- {
- temp=head;
- while(temp!=NULL)
- {
- printf("%s ",temp->b);
- temp=temp->ptr;
- }
- printf("\n");
- }
- void push(char c[50])
- {
- a=(x*)malloc(sizeof(x));
- strcpy(a->b, c);
- a->ptr=NULL;
- if(head==NULL)
- {
- head = a;
- }
- else
- {
- a->ptr=head;
- head=a;
- }
- }
- void pop()
- {
- temp=head;
- head=head->ptr;
- free(temp);
- }
- int main()
- {
- printf("Input The Size Of The Stack ");
- int n,b,d,e=0;
- char c[50];
- scanf("%d",&n);
- printf("Input Name\n");
- for(b=0; b<n; b++)
- {
- scanf("%s",c);
- push(c);
- }
- print();
- scanf("%d",&n);
- for(b=0; b<n; b++)
- {
- pop();
- }
- print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement