Advertisement
darkjessy94

eliminazione_lista_bidirezionale

Sep 5th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct node
  5. {
  6. int data;
  7. struct node* next;
  8. struct node* prev;
  9. };
  10.  
  11. typedef struct node Node;
  12. typedef Node* pNode;
  13.  
  14. pNode eliminazione_lista_bidirezionale(pNode lista, int elem)
  15. {
  16. pNode prec,curr;
  17. curr=lista;
  18.  
  19. while(curr!=NULL && elem > curr->data)
  20. {
  21. curr=curr->next;
  22. }
  23.  
  24. if(curr->data == elem)
  25. {
  26. if(curr->prev==NULL)///in testa
  27. {
  28. lista=curr->next;
  29. lista->prev=NULL;
  30. free(curr);
  31. }
  32. else if(curr->next==NULL)///in fondo
  33. {
  34. prec=curr->prev;
  35. prec->next=NULL;
  36. free(curr);
  37. }
  38. else ///in mezzo
  39. {
  40. prec=curr->prev;
  41. prec->next=curr->next;
  42. free(curr);
  43. }
  44. }
  45. return lista;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement