mittimus

File LIST.c

Jul 17th, 2012
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.43 KB | None | 0 0
  1. #include<stdlib.h>
  2. #define LISTAVUOTA NULL
  3. typedef short boolean;
  4. typedef struct nodoList {
  5. tipobaseList info;
  6. struct nodoList *next;
  7. } *list;
  8. typedef list position;
  9. position End(list l){
  10. if (l==LISTAVUOTA) return(LISTAVUOTA);
  11. while (l->next!=LISTAVUOTA)
  12. l=l->next;
  13. return(l);
  14. }
  15. position First(list l) {
  16. return(LISTAVUOTA); /*se la lista è vuota torna END(l) */
  17. }
  18. void MakeNullList(list *l){
  19. *l=LISTAVUOTA;
  20. }
  21. boolean EmptyList(list l){
  22. return(l==LISTAVUOTA);
  23. }
  24. boolean FullList(list l){
  25. return(0);
  26. }
  27. void InsertList(list *l, position p, tipobaseList x){
  28. struct nodoList * temp;
  29. if (!FullList(*l)) {
  30. temp=(struct nodoList *) malloc(sizeof(struct nodoList));
  31. temp->info=x;
  32. if (p==LISTAVUOTA) {
  33. temp->next=*l;
  34. *l=temp;
  35. } else {
  36. temp->next=p->next;
  37. p->next=temp;
  38. }
  39. }
  40. }
  41.  
  42. void DeleteList(list *l, position p){
  43. struct nodoList * tmp;
  44. if (!EmptyList(*l))
  45. if (p==LISTAVUOTA) {
  46. tmp=(*l)->next;
  47. free (*l);
  48. *l=tmp;
  49. } else {
  50. tmp=p->next;
  51. p->next=tmp->next;
  52. free (tmp);
  53. }
  54. }
  55. position Locate(list l, tipobaseList x){
  56. if (!EmptyList(l)) {
  57. if (!Confronta(l->info,x)) return(LISTAVUOTA);
  58. while (l->next!=LISTAVUOTA) {
  59. if (!Confronta(l->next->info,x)) return(l);
  60. l=l->next;
  61. }
  62. return(l);
  63. }
  64. }
  65. tipobaseList Retrieve(list l, position p)
  66. {
  67. if (!EmptyList(l))
  68. if (p==LISTAVUOTA) return(l->info);
  69. else return(p->next->info);
  70. }
  71. position Next(list l, position p)
  72. {
  73. if (p==LISTAVUOTA) return(l);
  74. else return(p->next);
  75. }
Advertisement
Add Comment
Please, Sign In to add comment