mittimus

Funzioni Main Lista

Jul 17th, 2012
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.94 KB | None | 0 0
  1. #include<stdio.h>
  2. #include "TipobaseList.h"
  3. #include "ListaC.h"
  4. void visita(list);
  5. void insord(list *, tipobaseList);
  6. list lt;
  7. main(){
  8. short s;
  9. tipobaseList elem;
  10. position pos;
  11. MakeNullList(&lt);
  12. do {
  13. printf("\n\nMenu di Operazioni ");
  14. printf("\n1-Inserimento Ordinato ");
  15. printf("\n2-Ricerca ");
  16. printf("\n3-Cancellazione ");
  17. printf("\n4-Visita Lista ");
  18. printf("\n5-Modifica Elemento ");
  19. printf("\n6-Fine ");
  20. printf("\nInserisci la scelta ---> ");
  21. scanf("%d",&s);
  22. FLUSH;
  23. switch(s) {
  24.  
  25. case 1 :
  26. if (FullList(lt)) printf("\nLista piena ");
  27. else {
  28. LeggiElementoList(&elem);
  29. insord(&lt,elem);
  30. }
  31. break;
  32. case 2 :
  33. if (EmptyList(lt)) printf("\nLista Vuota ");
  34. else {
  35. CercaElementoList(&elem);
  36. pos=Locate(lt,elem);
  37. if (pos!=End(lt)){
  38. printf("\nElemento Trovato ");
  39. VisualizzaElementoList(Retrieve(lt,pos));
  40. }else printf("\nElemento non Trovato ");
  41. }
  42. break;
  43. case 3 :
  44. if (EmptyList(lt)) printf("\nLista Vuota ");
  45. else {
  46. CercaElementoList(&elem);
  47. pos=Locate(lt,elem);
  48. if (pos!=End(lt)) {
  49. DeleteList(&lt,pos);
  50. printf("\nElemento Eliminato ");
  51. }
  52. else printf("\nElemento non Trovato ");
  53. }
  54. break;
  55. case 4 :
  56. if (EmptyList(lt)) printf("\nLista Vuota ");
  57. else visita(lt);
  58. break;
  59. case 5 :
  60. if (EmptyList(lt)) printf("\nLista Vuota ");
  61. else {
  62. CercaElementoList(&elem);
  63. pos=Locate(lt,elem);
  64. if (pos!=End(lt)) {
  65. elem=Retrieve(lt,pos);
  66. ModificaElementoList(&elem);
  67. DeleteList(&lt,pos);
  68. insord(&lt,elem);
  69. printf("\nElemento Modificato ");
  70. } else printf("\nElemento non Trovato ");
  71. }
  72. }
  73. } while (s<6);
  74. }
  75.  
  76. void visita(list l){
  77. position p,u;
  78. tipobaseList x;
  79. p=First(l);
  80. u=End(l);
  81. while (p!=u) {
  82. x=Retrieve(l,p);
  83. VisualizzaElementoList(x);
  84. p=Next(l,p);
  85. }
  86. }
  87. void insord(list *l, tipobaseList x)
  88. {
  89. position p,u;
  90. tipobaseList tmp;
  91. if (EmptyList(*l)) InsertList(l,First(*l),x);
  92. else {
  93. p=First(*l);
  94. u=End(*l);
  95. while (p!=u) {
  96. tmp=Retrieve(*l,p);
  97. if (Confronta(tmp,x)<0) p=Next(*l,p);
  98. else break;
  99. }
  100. InsertList(l,p,x);
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment