Advertisement
Guest User

edigno

a guest
Jan 19th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. //List structure:
  5. struct El {
  6. int info;
  7. struct El *next;
  8. };
  9.  
  10. typedef struct El ElementoLista;
  11.  
  12.  
  13.  
  14. // Functions/Procedure to be implemented:
  15.  
  16. void readList(ElementoLista **lista, int dis);
  17. int maxDistance(ElementoLista *lista);
  18. void CancellaMax(ElementoLista **lista, int maxdis);
  19.  
  20.  
  21. //Function to print all the elements of the list:
  22. void printList(ElementoLista *list) {
  23. printf("(");
  24. while (list != NULL) {
  25. printf("%d ", list->info);
  26. list = list->next;
  27. }
  28. printf(")\n");
  29. }
  30.  
  31. int main() {
  32. ElementoLista *list=NULL, *list_aux=NULL;
  33. int boundis, maxdis;
  34.  
  35. //Read the bounded distance
  36. scanf("%d", &boundis);
  37.  
  38. //Read and print the list
  39. list_aux=readList(&list, boundis);
  40. printf("La lista bounded-%d e':\n", boundis);
  41. if(list_aux != NULL)
  42. {
  43. list = list_aux;
  44. list_aux = NULL;
  45. }
  46.  
  47. printList(list);
  48.  
  49. //Compute and print the maxdistance of the list
  50. maxdis = maxDistance(list);
  51. printf("La distanza massima e':\n%d\n",maxdis);
  52.  
  53. //Remove the elements at distance maxdistance
  54. list_aux = CancellaMax(&list, maxdis);
  55. printf("La lista modificata e':\n");
  56. if(list_aux != NULL) list = list_aux;
  57. printList(list);
  58.  
  59.  
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement