Advertisement
Saleh127

even odd

Feb 28th, 2020
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef struct node
  4. {
  5. int data;
  6. struct node *next;
  7. } node;
  8. node *head=NULL;
  9. node *temp=NULL;
  10. int count=0;
  11. void creatlist()
  12. {
  13. node *newnode=(node*)malloc(sizeof(node));
  14. scanf("%d",&newnode->data);
  15. newnode->next=NULL;
  16. if(head==NULL)
  17. {
  18. head=newnode;
  19. }
  20. else
  21. {
  22. temp=head;
  23. while(temp->next!=NULL)
  24. {
  25. temp=temp->next;
  26. }
  27. temp->next=newnode;
  28. }
  29. }
  30. printf(int a)
  31. {
  32. int odd=0,even=0;
  33. temp=head;
  34. while(temp!=NULL)
  35. {
  36. if(temp->data%2==0)
  37. even++;
  38. else
  39. odd++;
  40. }
  41. if(even==0)
  42. {
  43. printf("Even list is empty \n");
  44. }
  45. else
  46. {
  47. printf("Even list:\n");
  48. temp=head;
  49. while(temp!=NULL)
  50. {
  51. if(temp->data%2==0)
  52. {
  53. printf("%d ",temp->data);
  54. }
  55. temp=temp->next;
  56. }
  57. }
  58. if(odd==0)
  59. {
  60. printf("Odd list is empty \n");
  61. }
  62. else
  63. {
  64. printf("Odd list:\n");
  65. temp=head;
  66. while(temp!=NULL)
  67. {
  68. if(temp->data%2==1)
  69. {
  70. printf("%d ",temp->data);
  71. }
  72. temp=temp->next;
  73. }
  74. }
  75. }
  76. int main()
  77. {
  78. int i,a;
  79. scanf("%d",&a);
  80. for(i=1; i<=a; i++)
  81. {
  82. creatlist();
  83. }
  84. printf(a);
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement