Guest User

Untitled

a guest
Jul 11th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.45 KB | None | 0 0
  1. void insereLista(NO **cabeca, int elemento) {
  2.     NO* aux = (NO*)malloc(sizeof(NO));
  3.     aux->prox = *cabeca;
  4.     aux->dado = elemento;
  5.  
  6.     if(*cabeca == NULL || elemento < (*cabeca)->dado)
  7.         *cabeca = aux;
  8.     else {
  9.         NO* ptr = *cabeca;
  10.  
  11.         while(ptr->prox != NULL && ptr->prox->dado < elemento)
  12.             ptr = ptr->prox;
  13.  
  14.         if(ptr->dado != elemento && ptr->prox != NULL && ptr->prox->dado != elemento){
  15.             aux->prox = ptr->prox;
  16.             ptr->prox = aux;
  17.         }
  18.     }
  19. }
Add Comment
Please, Sign In to add comment