Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct node
- {
- int data;
- struct node* next;
- }node;
- node* top = NULL;
- void push(int x)
- {
- node* Newnode;
- Newnode=(node*)malloc(sizeof(node));
- Newnode->data=x;
- Newnode->next=top;
- top=Newnode;
- }
- void pop()
- {
- node* temp;
- temp=top;
- top=top->next;
- temp->next=NULL;
- free(temp);
- }
- void print()
- {
- node* temp;
- if(top==NULL)
- {
- printf("stack is empty:");
- }
- else
- {
- temp=top;
- while(temp!=NULL)
- {
- printf("data %d\n",temp->data);
- temp=temp->next;
- }
- }
- }
- int main(){
- int x,n,i,m;
- printf("Enter input number: ");
- scanf("%d",&n);
- for(i=0;i<n;i++){
- printf("Enter stack data: ");
- scanf("%d",&x);
- push(x);}
- print();
- printf("Enter the number to delete");
- scanf("%d",&m);
- pop();
- print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment