Guest User

Untitled

a guest
Jun 22nd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1.  
  2. int add_testimone (Testimone* t, Element** l)
  3. {
  4.     Element *temp;
  5.     Element *e = new_element (t);
  6.     /*inserimento in una lista non inizializzata*/
  7.     if (*l == NULL)
  8.     {
  9.         *l=my_malloc(sizeof (Element*));
  10.         e->next = NULL;
  11.         *l=e;
  12.         return 1;
  13.     }
  14.      temp = *l;
  15.     /*inserimento al primo posto*/
  16.     if (strcmp(e->key, (*l)->key) < 0)
  17.     {
  18.         head_insert(e,l);
  19.         return 1;
  20.     }
  21.  
  22.     while (1)
  23.     {
  24.         if (temp->key == e->key)
  25.         {
  26.             free(e);
  27.             return 0;
  28.         }
  29.         /*inserimento nell'ultima posizione*/
  30.         if (temp->next == NULL)
  31.         {
  32.             temp->next = e;
  33.             return 1;
  34.         }
  35.        
  36.         /*inserimento in mezzo alla lista*/
  37.         if (strcmp(e->key, temp->next->key)<0)
  38.         {
  39.             e->next = temp->next;
  40.             temp->next = e;
  41.             return 1;
  42.         }
  43.         temp = temp->next;
  44.     }
  45. }
Add Comment
Please, Sign In to add comment