Código:
#include <stdio.h>
struct nodo{
int dato;
struct nodo *anterior;
};
int main(){
struct nodo *tmp=NULL, *fin=NULL;
int opcion;
while(opcion !=4)
{
switch(opcion)
{
printf("******* "
"Elija una opcion\n"
".......1 Ingrese dato\n"
".......2 Borrar dato\n"
".......3 Mostrar\n"
".......4 Salir\n");
scanf("%d", &opcion);
case 1: //Ingreso
tmp = (struct nodo*)malloc(sizeof(struct nodo));
tmp -> anterior = fin;
printf("ingrese un numero\n");
scanf("%d", &tmp->dato);
fin=tmp;
break;
case 2: //Borrar
tmp=fin;
fin=tmp->anterior;
free(tmp);
tmp=fin;
break;
case 3: //Mostrar
tmp=fin;
while(tmp!=NULL)
{
printf("%d", tmp->dato);
tmp=tmp->anterior;
}
break;
case 4: //Salir
printf(*****"Hasta pronto"*****);
break;
default:
printf("Intentelo otra vez");
break;
}
}
}
struct nodo{
int dato;
struct nodo *anterior;
};
int main(){
struct nodo *tmp=NULL, *fin=NULL;
int opcion;
while(opcion !=4)
{
switch(opcion)
{
printf("******* "
"Elija una opcion\n"
".......1 Ingrese dato\n"
".......2 Borrar dato\n"
".......3 Mostrar\n"
".......4 Salir\n");
scanf("%d", &opcion);
case 1: //Ingreso
tmp = (struct nodo*)malloc(sizeof(struct nodo));
tmp -> anterior = fin;
printf("ingrese un numero\n");
scanf("%d", &tmp->dato);
fin=tmp;
break;
case 2: //Borrar
tmp=fin;
fin=tmp->anterior;
free(tmp);
tmp=fin;
break;
case 3: //Mostrar
tmp=fin;
while(tmp!=NULL)
{
printf("%d", tmp->dato);
tmp=tmp->anterior;
}
break;
case 4: //Salir
printf(*****"Hasta pronto"*****);
break;
default:
printf("Intentelo otra vez");
break;
}
}
}
Me da 2 errores, me podrian ayudar en eso ademas despues tengo que hacer que borre le primer dato que le ingrese ya que este prog borra el ultimo dato.
Quedaria asi:
Código:
#include <stdio.h>
struct nodo{
int dato;
struct nodo *siguiente;
};
int main(){
struct nodo *inicio=NULL, *tmp=NULL, *fin=NULL;
int opcion;
while(opcion !=4)
{
switch(opcion)
{
printf("******* "
"Elija una opcion\n"
".......1 Ingrese dato\n"
".......2 Borrar dato\n"
".......3 Mostrar\n"
".......4 Salir\n");
scanf("%d", &opcion);
case 1: //Ingreso
tmp = (struct nodo*)malloc(sizeof(struct nodo));
tmp -> siguiente = inicio;
printf("ingrese un numero\n");
scanf("%d", &tmp->dato);
inicio=tmp;
break;
case 2: //Borrar
inicio =fin;
inicio=tmp->siguiente;
free(tmp);
tmp=inicio;
break;
case 3: //Mostrar
tmp=inicio;
while(tmp!=NULL)
{
printf("%d", tmp->dato);
tmp=tmp->siguiente;
}
break;
case 4: //Salir
printf(*****"Hasta pronto"*****);
break;
default:
printf("Intentelo otra vez");
break;
}
}
}
struct nodo{
int dato;
struct nodo *siguiente;
};
int main(){
struct nodo *inicio=NULL, *tmp=NULL, *fin=NULL;
int opcion;
while(opcion !=4)
{
switch(opcion)
{
printf("******* "
"Elija una opcion\n"
".......1 Ingrese dato\n"
".......2 Borrar dato\n"
".......3 Mostrar\n"
".......4 Salir\n");
scanf("%d", &opcion);
case 1: //Ingreso
tmp = (struct nodo*)malloc(sizeof(struct nodo));
tmp -> siguiente = inicio;
printf("ingrese un numero\n");
scanf("%d", &tmp->dato);
inicio=tmp;
break;
case 2: //Borrar
inicio =fin;
inicio=tmp->siguiente;
free(tmp);
tmp=inicio;
break;
case 3: //Mostrar
tmp=inicio;
while(tmp!=NULL)
{
printf("%d", tmp->dato);
tmp=tmp->siguiente;
}
break;
case 4: //Salir
printf(*****"Hasta pronto"*****);
break;
default:
printf("Intentelo otra vez");
break;
}
}
}
Asi quedaria?????
Espero su ayuda ya que tengo prueba de esto en unos dias

Salu2!










Autor


En línea
