fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef int NODE;
  5. struct EDGE {
  6. NODE nodo1; //primo nodo dell'arco
  7. NODE nodo2; //altro nodo dell'arco
  8. struct EDGE *next; //successivi archi
  9. };
  10. typedef struct EDGE* EDGELIST;
  11.  
  12. void deleteArco(EDGELIST* t, NODE x, NODE y){
  13. if ((*t) != NULL) {
  14. if( (*t)->nodo1 == x && (*t)->nodo2 == y){
  15. EDGELIST p = (*t);
  16. (*t) = (*t)->next;
  17. free(p);
  18. }else
  19. deleteArco(&(*t)->next, x, y);
  20. }
  21. }
  22.  
  23. void insertArco(EDGELIST* t, NODE x, NODE y){
  24. EDGELIST e = (EDGELIST)malloc(sizeof(struct EDGE));
  25. e->nodo1 = x;
  26. e->nodo2 = y;
  27. e->next = *t;
  28. *t = e;
  29. }
  30.  
  31. void printEdgeList(EDGELIST t){
  32. while(t != NULL) {
  33. printf("%d->%d\n", t->nodo1, t->nodo2);
  34. t = t->next;
  35. }
  36. }
  37.  
  38. int main(void) {
  39. EDGELIST t = NULL;
  40.  
  41. insertArco(&t, 1, 2);
  42. insertArco(&t, 2, 1);
  43. insertArco(&t, 3, 1);
  44. insertArco(&t, 3, 5);
  45. printEdgeList(t);
  46.  
  47. puts("\nDeleting 2->1");
  48. deleteArco(&t, 2, 1);
  49. printEdgeList(t);
  50.  
  51. puts("\nDeleting 2->5 (not in list)");
  52. deleteArco(&t, 2, 5);
  53. printEdgeList(t);
  54.  
  55. return 0;
  56. }
  57.  
Success #stdin #stdout 0s 4256KB
stdin
Standard input is empty
stdout
3->5
3->1
2->1
1->2

Deleting 2->1
3->5
3->1
1->2

Deleting 2->5 (not in list)
3->5
3->1
1->2