Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<stdbool.h>
- typedef struct Deep
- {
- int d;
- struct Deep *p;
- } node;
- node *h;
- int main()
- {
- creaeList();
- printList();
- removeList();
- printList();
- }
- void removeList(){
- node *list=h;
- again:
- if(list->d==0){
- node *tmp=h;
- h=h->p;
- free(tmp);
- }
- list=h;
- if(list->d==0)
- goto again;
- while(list->p){
- if(list->p->d==0){
- node *tmp=list->p;
- list->p=list->p->p;
- free(tmp);
- continue;
- }
- list=list->p;
- }
- }
- void creaeList()
- {
- node *list=(node*)malloc(sizeof(node));
- int a,b;
- scanf("%d",&a);
- printf("Enter Number : ");
- scanf("%d",&b);
- list->d=b;
- list->p=NULL;
- h=list;
- loop(a-1);
- }
- void addLast(int a)
- {
- node *list=h;
- while(list->p)
- {
- list=list->p;
- }
- node *tmp=(node*)malloc(sizeof(node));
- tmp->d=a;
- tmp->p=NULL;
- list->p=tmp;
- }
- void loop(n)
- {
- for(int i=1; i<=n; i++)
- {
- int a;
- scanf("%d",&a);
- addLast(a);
- }
- }
- void printList()
- {
- node *list=h;
- while(list)
- {
- printf("%d ",list->d);
- list=list->p;
- }
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement