Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include "TipobaseList.h"
- #include "ListaC.h"
- void visita(list);
- void insord(list *, tipobaseList);
- list lt;
- main(){
- short s;
- tipobaseList elem;
- position pos;
- MakeNullList(<);
- do {
- printf("\n\nMenu di Operazioni ");
- printf("\n1-Inserimento Ordinato ");
- printf("\n2-Ricerca ");
- printf("\n3-Cancellazione ");
- printf("\n4-Visita Lista ");
- printf("\n5-Modifica Elemento ");
- printf("\n6-Fine ");
- printf("\nInserisci la scelta ---> ");
- scanf("%d",&s);
- FLUSH;
- switch(s) {
- case 1 :
- if (FullList(lt)) printf("\nLista piena ");
- else {
- LeggiElementoList(&elem);
- insord(<,elem);
- }
- break;
- case 2 :
- if (EmptyList(lt)) printf("\nLista Vuota ");
- else {
- CercaElementoList(&elem);
- pos=Locate(lt,elem);
- if (pos!=End(lt)){
- printf("\nElemento Trovato ");
- VisualizzaElementoList(Retrieve(lt,pos));
- }else printf("\nElemento non Trovato ");
- }
- break;
- case 3 :
- if (EmptyList(lt)) printf("\nLista Vuota ");
- else {
- CercaElementoList(&elem);
- pos=Locate(lt,elem);
- if (pos!=End(lt)) {
- DeleteList(<,pos);
- printf("\nElemento Eliminato ");
- }
- else printf("\nElemento non Trovato ");
- }
- break;
- case 4 :
- if (EmptyList(lt)) printf("\nLista Vuota ");
- else visita(lt);
- break;
- case 5 :
- if (EmptyList(lt)) printf("\nLista Vuota ");
- else {
- CercaElementoList(&elem);
- pos=Locate(lt,elem);
- if (pos!=End(lt)) {
- elem=Retrieve(lt,pos);
- ModificaElementoList(&elem);
- DeleteList(<,pos);
- insord(<,elem);
- printf("\nElemento Modificato ");
- } else printf("\nElemento non Trovato ");
- }
- }
- } while (s<6);
- }
- void visita(list l){
- position p,u;
- tipobaseList x;
- p=First(l);
- u=End(l);
- while (p!=u) {
- x=Retrieve(l,p);
- VisualizzaElementoList(x);
- p=Next(l,p);
- }
- }
- void insord(list *l, tipobaseList x)
- {
- position p,u;
- tipobaseList tmp;
- if (EmptyList(*l)) InsertList(l,First(*l),x);
- else {
- p=First(*l);
- u=End(*l);
- while (p!=u) {
- tmp=Retrieve(*l,p);
- if (Confronta(tmp,x)<0) p=Next(*l,p);
- else break;
- }
- InsertList(l,p,x);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment