Advertisement
Guest User

Clase lista nro 1

a guest
May 27th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.58 KB | None | 0 0
  1. void recorrerlista(const t_lista *p,void (*mostrarinfo)(const t_info*))
  2. {
  3.     while(*p)
  4.     {
  5.         mostrarinfo (&(*p)->info);
  6.     }
  7. }
  8. void ordernar(t_lista *p,int (*comparar)(const t_info *,const t_info*))
  9. {
  10.     int marca = 1;
  11.     if(*p)
  12.         while(marca)
  13.         {
  14.             t_lista *q = p;
  15.             marca = 0;
  16.             while((*q)->sig)
  17.             {
  18.                 if(comparar(&(*q)->info,&(*q)->sig->info))
  19.                 {
  20.                     t_nodo *act = *q;
  21.                     t_nodo *sig = act->sig;
  22.                     t_nodo *sigsig = sig->sig;
  23.                     marca = 1;
  24.                     *q = sig;
  25.                     act->sig = sigsig;
  26.                     sig->sig = act;
  27.                 }
  28.                 q = &(*q)->sig;
  29.             }
  30.         }
  31.  
  32. }
  33.  
  34. int elimunicosNoOrdenada(t_lista *p,int (*comparar)(const t_info *,const t_info*))
  35. {
  36.     t_lista *q = p;
  37.     int veces,cant;
  38.     while(*q)
  39.     {
  40.         t_nodo *aux = *p;
  41.         veces = 2;
  42.         while(veces && aux)
  43.         {
  44.             if(comparar(&aux->info,&(*q)->info)==0)
  45.                 veces--;
  46.             aux = aux->sig;
  47.         }
  48.         if(veces ==1)
  49.         {
  50.             aux =*q;
  51.             *q= aux->sig;
  52.             cant =+1;
  53.             free(aux);
  54.         }
  55.         q =&(*q)->sig;
  56.     }
  57.     return cant;
  58. }
  59.  
  60.  
  61. int mostraralrevez(const t_lista *p,void (*mostrarinfo)(const t_info*))
  62. {
  63.     int cant;
  64.     if(*p)
  65.     {
  66.         cant = mostraralrevez(&(*p)->sig,mostrarinfo);
  67.         mostrarinfo(&(*p)->info);
  68.         return cant+1;
  69.     }
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement