Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct node
- {
- int a;
- struct node *next;
- } node;
- node *head=NULL;
- void Add_End(int x)
- {
- node *newnode;
- newnode=(node*)malloc(sizeof(node));
- newnode->a=x;
- newnode->next=NULL;
- if(head==NULL)
- {
- head=newnode;
- }
- else
- {
- node* current=head;
- while(current->next!=NULL)
- {
- current=current->next;
- }
- current->next=newnode;
- }
- }
- void evenodd()
- {
- node *list=head;node *temp;
- if(head==NULL)
- {
- printf("No value\n\n");
- }
- else if(head->a%2!=0)
- {
- temp=head;
- head=head->next;
- free(temp);
- evenodd();
- }
- else
- {
- list=head;
- while(list->next!=NULL)
- {
- if(list->next->a%2!=0)
- {
- temp=list->next;
- list->next=temp->next;
- free(temp);
- }
- list=list->next;
- }
- }
- }
- void display()
- {
- node*list=head;
- while(list!=NULL)
- {
- printf("Data: %d\n",list->a);
- list=list->next;
- }
- }
- int main()
- {
- int p,n,i,loc,x;
- head=NULL;
- printf("Input the Number of Node:");
- scanf("%d",&n);
- for(i=0; i<n; i++)
- {
- scanf("%d",&x);
- Add_End(x);
- }
- printf("Result:\n");
- evenodd();
- display();
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement