Advertisement
Guest User

aaaaaaaaaaa

a guest
Nov 13th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.46 KB | None | 0 0
  1. int ponerEnListaAcumulandoDuplicados(
  2.                                      tLista* p,
  3.                                      const tInfo* d,
  4.                                      int(*cmp)(const tInfo*,const tInfo*),
  5.                                      void(*acum)(tInfo*,const tInfo*)
  6.                                      )
  7.     ///VER LISTA
  8.     ///PREPARACION DE LOS PUNTEROS VERIFICANDO BORDES Y COMPARANDO
  9.     ///PREPARACION DEL NUEVO NODO
  10.     ///CONEXION DE LA LISTA CON EL NUEVO NODO
  11. {
  12.     tNodo* nue,
  13.          * act=*p,
  14.          * sig,
  15.          * ant;
  16.     int comparacion;
  17.  
  18.     if(act==NULL)
  19.     {
  20.         sig=NULL;
  21.         ant=NULL;
  22.     }
  23.     else
  24.     {
  25.         while(act->sig&&cmp(d,&act->info)>0)
  26.             act=act->sig;
  27.         while(act->ant&&cmp(d,&act->info)<0)
  28.             act=act->ant;
  29.         //ACT LISTO
  30.         comparacion=cmp(d,&act->info);
  31.  
  32.         if(comparacion==0)
  33.         {
  34.             acum(&act->info,d);
  35.             return 2;
  36.         }
  37.         if(comparacion<0)
  38.         {
  39.             sig=act;
  40.             ant=act->ant;
  41.         }
  42.         else
  43.         {
  44.             sig=act->sig;
  45.             ant=act;
  46.         }
  47.         //PUNTEROS LISTOS
  48.     }
  49.     //PREPARACION DEL NODO
  50.     nue=(tNodo*)malloc(sizeof(tNodo));
  51.     if(!nue)
  52.         return 1;
  53.     nue->info=*d;
  54.     nue->sig=sig;
  55.     nue->ant=ant;
  56.     //CABLEADO
  57.     if(ant)
  58.         ant->sig=nue;
  59.     if(sig)
  60.         sig->ant=nue;
  61.     *p=nue;
  62.     return 0;
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement