Advertisement
dsdeep

Delete Zero

Nov 3rd, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<stdbool.h>
  4. typedef struct Deep
  5. {
  6.     int d;
  7.     struct Deep *p;
  8. } node;
  9. node *h;
  10. int main()
  11. {
  12.     creaeList();
  13.     printList();
  14. removeList();
  15.     printList();
  16. }
  17. void removeList(){
  18. node *list=h;
  19. again:
  20. if(list->d==0){
  21.     node *tmp=h;
  22.     h=h->p;
  23.     free(tmp);
  24. }
  25. list=h;
  26. if(list->d==0)
  27.     goto again;
  28. while(list->p){
  29.     if(list->p->d==0){
  30.         node *tmp=list->p;
  31.         list->p=list->p->p;
  32.         free(tmp);
  33.     continue;
  34.     }
  35.     list=list->p;
  36. }
  37. }
  38.  
  39.  
  40. void creaeList()
  41. {
  42.     node *list=(node*)malloc(sizeof(node));
  43.     int a,b;
  44.     scanf("%d",&a);
  45.     printf("Enter Number : ");
  46.     scanf("%d",&b);
  47.     list->d=b;
  48.     list->p=NULL;
  49.     h=list;
  50.     loop(a-1);
  51. }
  52. void addLast(int a)
  53. {
  54.     node *list=h;
  55.     while(list->p)
  56.     {
  57.         list=list->p;
  58.     }
  59.     node *tmp=(node*)malloc(sizeof(node));
  60.     tmp->d=a;
  61.     tmp->p=NULL;
  62.     list->p=tmp;
  63. }
  64. void loop(n)
  65. {
  66.     for(int i=1; i<=n; i++)
  67.     {
  68.         int a;
  69.         scanf("%d",&a);
  70.         addLast(a);
  71.     }
  72. }
  73. void printList()
  74. {
  75.     node *list=h;
  76.     while(list)
  77.     {
  78.         printf("%d ",list->d);
  79.         list=list->p;
  80.     }
  81.     printf("\n");
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement