fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct node
  5. {
  6. int value;
  7. struct node *prev,*next;
  8. };
  9.  
  10. typedef struct
  11. {
  12. struct node *head,*tail;
  13. }List;
  14.  
  15. struct node *NewNode(int value,struct node *prev,struct node *next)
  16. {
  17. struct node *ret;
  18. ret=(struct node*)malloc(sizeof(struct node));
  19. ret->value=value;
  20. ret->prev=prev;
  21. ret->next=next;
  22. }
  23.  
  24. void Add(List *L,int value)
  25. {
  26. struct node *tmp;
  27. tmp=NewNode(value,L->tail,NULL);
  28. if(L->tail) L->tail->next=tmp;
  29. else L->head=tmp;
  30. L->tail=tmp;
  31. }
  32.  
  33. void Show(List *L)
  34. {
  35. struct node *i;
  36. for(i=L->head;i;i=i->next) printf(" %d",i->value);
  37. printf("\n");
  38. }
  39.  
  40. void Del(List *L,struct node *del)
  41. {
  42. if(del->prev) del->prev->next=del->next;
  43. else L->head=del->next;
  44. if(del->next) del->next->prev=del->prev;
  45. else L->tail=del->prev;
  46. }
  47.  
  48. void DelEven(List *L)
  49. {
  50. struct node *tmp,*next;
  51. tmp=L->head;
  52. while(tmp)
  53. {
  54. next=tmp->next;
  55. if(!(tmp->value&1)) Del(L,tmp);
  56. tmp=next;
  57. }
  58. }
  59.  
  60. int main()
  61. {
  62. int i;
  63. List L={NULL,NULL};
  64. for(i=0;i<10;++i) Add(&L,i);
  65. printf("Przed:\n");
  66. Show(&L);
  67. DelEven(&L);
  68. printf("Po:\n");
  69. Show(&L);
  70. return 0;
  71. }
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
Przed:

Po: