Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef struct node
- {
- int data;
- struct node *next;
- } node;
- node *head=NULL;
- node *temp=NULL;
- int count=0;
- void creatlist()
- {
- node *newnode=(node*)malloc(sizeof(node));
- scanf("%d",&newnode->data);
- newnode->next=NULL;
- if(head==NULL)
- {
- head=newnode;
- }
- else
- {
- temp=head;
- while(temp->next!=NULL)
- {
- temp=temp->next;
- }
- temp->next=newnode;
- }
- }
- printf(int a)
- {
- int odd=0,even=0;
- temp=head;
- while(temp!=NULL)
- {
- if(temp->data%2==0)
- even++;
- else
- odd++;
- }
- if(even==0)
- {
- printf("Even list is empty \n");
- }
- else
- {
- printf("Even list:\n");
- temp=head;
- while(temp!=NULL)
- {
- if(temp->data%2==0)
- {
- printf("%d ",temp->data);
- }
- temp=temp->next;
- }
- }
- if(odd==0)
- {
- printf("Odd list is empty \n");
- }
- else
- {
- printf("Odd list:\n");
- temp=head;
- while(temp!=NULL)
- {
- if(temp->data%2==1)
- {
- printf("%d ",temp->data);
- }
- temp=temp->next;
- }
- }
- }
- int main()
- {
- int i,a;
- scanf("%d",&a);
- for(i=1; i<=a; i++)
- {
- creatlist();
- }
- printf(a);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement