Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct no *Lista;
  5.  
  6. typedef struct no{
  7.     int no;
  8.     Lista previous;
  9.     Lista next;
  10. }No;
  11.  
  12. Lista criaLista(){
  13.     Lista aux;
  14.     aux = (Lista) malloc(sizeof(No));
  15.     if(aux!=NULL){
  16.         aux->no = 0;
  17.         aux->next = NULL;
  18.     }
  19.     return aux;
  20.  
  21. }
  22.  
  23. int listaVazia(Lista lista){
  24.     return (lista->next == NULL ? 1 : 0);
  25. }
  26.  
  27. void destroiLista(Lista lista){
  28.     Lista temp_ptr;
  29.     while(listaVazia(lista) == 0){
  30.         temp_ptr = lista;
  31.         lista = lista->next;
  32.         free(temp_ptr);
  33.     }
  34.     free(lista);
  35. }
  36.  
  37. void insereLista(Lista lista,int valor){
  38.     Lista novo;
  39.     Lista ptr =lista;
  40.     Lista ptr2= lista->previous;
  41.     novo=(Lista)malloc(sizeof(No));
  42.     while(ptr!=NULL){
  43.         ptr2=ptr2->next;
  44.         ptr=ptr->next;
  45.     }
  46.     novo->no=valor;
  47.     ptr->next=novo;
  48.     novo->next=NULL;
  49.     lista->no++;
  50. }
  51.  
  52. void imprimeLista(Lista lista){
  53.     Lista p;
  54.     p=lista->next;
  55.     while(p!=NULL){
  56.         printf("Valor:%d\n",p->no);
  57.         p=p->next;
  58.     }
  59. }
  60.  
  61. int procuraLista(Lista lista,int valor){
  62.     Lista atual = lista->next;
  63.     while (atual!=NULL){
  64.         if(atual->no == valor){
  65.             return 1;
  66.         }
  67.         atual = atual->next;
  68.     }
  69.     return 0;
  70. }
  71.  
  72. void eliminaLista(Lista lista,int valor){
  73.     Lista p = lista->next;
  74.     Lista ant,atual;
  75.     while(p!=NULL){
  76.         if(procuraLista(lista,valor)==1){
  77.             ant = p;
  78.             atual = ant->next;
  79.             if(atual!=NULL){
  80.                 ant->next=atual->next;
  81.                 free(atual);
  82.                 lista->no--;
  83.             }
  84.         }
  85.         p = p->next;
  86.     }
  87.  
  88. }
  89.  
  90. int main()
  91. {
  92.    
  93.     return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement