Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void crearListaD(tListaD *lista)
- {
- *lista=NULL;
- }
- int insertarOrdenadoD(tListaD *lista,const void *dato,unsigned tam,int(*cmp)(const void *d1,const void *d2))
- {
- tNodo *nue,
- *act=*lista,
- *auxAnt,
- *auxSig;
- if(!(nue=malloc(sizeof(tNodo))))
- return -1;
- if(!(nue->dato=malloc(tam)))
- {
- free(nue);
- return -1;
- }
- memcpy(nue->dato,dato,tam);
- nue->tam=tam;
- if(!(*lista))
- {
- auxSig=NULL;
- auxAnt=NULL;
- }
- else
- {
- while(act->ant && cmp(dato,act->dato)<0)
- act=act->ant;
- while(act->sig && cmp(dato,act->dato)>=0)
- act=act->sig;
- if(cmp(dato,act->dato) > 0)
- {
- auxSig=act->sig;
- auxAnt=act;
- }
- else
- {
- auxSig=act;
- auxAnt=act->ant;
- }
- }
- nue->sig=auxSig;
- nue->ant=auxAnt;
- if(auxAnt)
- auxAnt->sig=nue;
- if(auxSig)
- auxSig->ant=nue;
- *lista=nue;
- return 1;
- }
- void recorrerListaD(tListaD *lista,void(*accion)(void *dato))
- {
- tNodo *act=*lista,
- *auxSig,
- *auxAnt;
- if(!(*lista))
- return;
- auxSig=act->sig;
- auxAnt=act->ant;
- while(auxAnt)
- {
- act=auxAnt;
- auxAnt=act->ant;
- auxSig=act->sig;
- }
- while(act)
- {
- accion(act->dato);
- act=auxSig;
- if(act)
- {
- auxSig=act->sig;
- auxAnt=act->ant;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement