Advertisement
rony-Rony_05

Untitled

Nov 11th, 2019
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.46 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. typedef struct node
  5. {
  6.  
  7.     int a;
  8.     struct node *next;
  9. } node;
  10.  
  11. node *head=NULL;
  12. void Add_End(int x)
  13. {
  14.  
  15.     node *newnode;
  16.     newnode=(node*)malloc(sizeof(node));
  17.     newnode->a=x;
  18.     newnode->next=NULL;
  19.     if(head==NULL)
  20.     {
  21.         head=newnode;
  22.     }
  23.     else
  24.     {
  25.         node* current=head;
  26.         while(current->next!=NULL)
  27.         {
  28.             current=current->next;
  29.  
  30.         }
  31.         current->next=newnode;
  32.     }
  33. }
  34.  
  35. void evenodd()
  36. {
  37.     node *list=head;node *temp;
  38.     if(head==NULL)
  39.     {
  40.         printf("No value\n\n");
  41.     }
  42.     else if(head->a%2!=0)
  43.     {
  44.         temp=head;
  45.         head=head->next;
  46.         free(temp);
  47.         evenodd();
  48.     }
  49.  
  50.      else
  51.     {
  52.             list=head;
  53.         while(list->next!=NULL)
  54.         {
  55.             if(list->next->a%2!=0)
  56.             {
  57.                 temp=list->next;
  58.                 list->next=temp->next;
  59.                 free(temp);
  60.             }
  61.             list=list->next;
  62.         }
  63.     }
  64. }
  65.  
  66. void display()
  67. {
  68.     node*list=head;
  69.     while(list!=NULL)
  70.     {
  71.         printf("Data: %d\n",list->a);
  72.  
  73.         list=list->next;
  74.     }
  75. }
  76. int main()
  77.  
  78. {
  79.     int p,n,i,loc,x;
  80.     head=NULL;
  81.     printf("Input the Number of Node:");
  82.     scanf("%d",&n);
  83.     for(i=0; i<n; i++)
  84.     {
  85.         scanf("%d",&x);
  86.         Add_End(x);
  87.  
  88.     }
  89.     printf("Result:\n");
  90.     evenodd();
  91.     display();
  92.  
  93.  
  94.  
  95.     return;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement