Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct no *Lista;
- typedef struct no{
- int no;
- Lista previous;
- Lista next;
- }No;
- Lista criaLista(){
- Lista aux;
- aux = (Lista) malloc(sizeof(No));
- if(aux!=NULL){
- aux->no = 0;
- aux->next = NULL;
- }
- return aux;
- }
- int listaVazia(Lista lista){
- return (lista->next == NULL ? 1 : 0);
- }
- void destroiLista(Lista lista){
- Lista temp_ptr;
- while(listaVazia(lista) == 0){
- temp_ptr = lista;
- lista = lista->next;
- free(temp_ptr);
- }
- free(lista);
- }
- void insereLista(Lista lista,int valor){
- Lista novo;
- Lista ptr =lista;
- Lista ptr2= lista->previous;
- novo=(Lista)malloc(sizeof(No));
- while(ptr!=NULL){
- ptr2=ptr2->next;
- ptr=ptr->next;
- }
- novo->no=valor;
- ptr->next=novo;
- novo->next=NULL;
- lista->no++;
- }
- void imprimeLista(Lista lista){
- Lista p;
- p=lista->next;
- while(p!=NULL){
- printf("Valor:%d\n",p->no);
- p=p->next;
- }
- }
- int procuraLista(Lista lista,int valor){
- Lista atual = lista->next;
- while (atual!=NULL){
- if(atual->no == valor){
- return 1;
- }
- atual = atual->next;
- }
- return 0;
- }
- void eliminaLista(Lista lista,int valor){
- Lista p = lista->next;
- Lista ant,atual;
- while(p!=NULL){
- if(procuraLista(lista,valor)==1){
- ant = p;
- atual = ant->next;
- if(atual!=NULL){
- ant->next=atual->next;
- free(atual);
- lista->no--;
- }
- }
- p = p->next;
- }
- }
- int main()
- {
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement