Está en la página 1de 2

PROBLEMA EN LENGUAJE C :

#include <stdio.h>
#include <stdlib.h>
struct lista{
int info ;
struct lista* sig;
};
typedef struct lista Tlista;
Tlista* inicializar(){
return NULL;
}
Tlista* insertar(Tlista* lst,int valor){
Tlista* nuevo;
nuevo=(Tlista*)malloc(sizeof(Tlista));
nuevo->info=valor;
nuevo->sig =lst;
return nuevo;
}
void recorrer(Tlista* lst){
Tlista* aux=lst;
while (aux!=NULL){
printf("%d ->",aux->info);
aux=aux->sig;
}
printf("NULL\n");
}
int leer(){
int temp;
printf("Dato: ");
scanf("%d",&temp);
return temp;
}
Tlista* remover(Tlista* lst,int dato){
Tlista* ant=NULL;
Tlista* act=lst;
while (act!=NULL && act->info!=dato){
ant=act;
act=act->sig;
}
//no se encontro el dato
if (act==NULL)
return lst;
if (ant==NULL) //dato esta en el primer nodo
lst=act->sig;
else
//dato esta al interior de la lista
ant->sig=act->sig;
free(act);
return lst;
}
int main(){
Tlista* lst;
int dato;
lst=inicializar();
dato=leer();
lst=insertar(lst,dato);
lst=insertar(lst,16);

lst=insertar(lst,21);
lst=insertar(lst,35);
recorrer(lst);
printf("Eliminando 35\n");
lst=remover(lst,35);
recorrer(lst);
printf("Eliminando 16\n");
lst=remover(lst,16);
recorrer(lst);
return 0;
}

También podría gustarte