[C con Clase] Como eliminar un nodo de una lista
David Fire
ddfire en gmail.com
Mar Abr 20 04:05:39 CEST 2010
seria algo asi como
*agenda temp;
temp=auxiliar->sig;
auxilar->sig=temp->sig;
free(temp);
David
El 19 de abril de 2010 19:43, Cristian David Villota Jacome <
cristian.vj23 en hotmail.com> escribió:
> Hola Amigos:
>
> Estoy programando una estructura de datos, bueno una lista con nodos que
> solicitan nombre y telefono; bueno he podido agregar nodos y mostrar en
> pantalla los que tengo pero no puedo eliminar un nodo, si alguien me puede
> ayuar con el algoritmo para hacerlo lo agradezco de antemano.
>
>
> #include<stdio.h>
> #include<conio.h>
> #include<stdlib.h>
>
>
> struct agenda
> {
> char nom[20];
> char tel[12];
> struct agenda*sig;
> };
>
>
>
> struct agenda*primero,*ultimo;
>
>
>
>
> void mostrar_menu()
> {
> printf("\n\n\t\tMENé");
> printf("\n\n\t1.A¤adir Elemento");
> printf("\n\t2.Borrar Elemento");
> printf("\n\t3.Mostrar Lista");
> printf("\n\t4.Salir");
>
> printf("\n\n\n\tElige una opci¢n: ");
> fflush(stdout);
> }
>
>
>
> void anadir_elemento()
> {
> struct agenda*nuevo;
> nuevo=(struct agenda*)malloc(sizeof(struct agenda));
>
> if(nuevo==NULL)
> {
> printf("NO HAY MEMORIA DISPONIBLE");
> }
>
> printf("\nNuevo Elemento\n");
>
>
> printf("Nombre: ");
> fflush(stdout);
> gets(nuevo->nom);
>
> printf("\nTelefono: ");
> fflush(stdout);
> gets(nuevo->tel);
>
> nuevo->sig=NULL;
>
> if(primero==NULL)
> {
> printf("\nPrimer Elemento\n");
> primero=nuevo;
> ultimo=nuevo;
> }
> else
> {
> ultimo->sig=nuevo;
> ultimo=nuevo;
> }
> getch();
> clrscr();
> }
>
>
>
>
>
> ///////////////////////
>
>
>
>
>
> void mostrar_lista()
> {
> struct agenda*auxiliar;
> int i;
> i=0;
> auxiliar=primero;
> printf("\n\nMostrando lista completa\n");
>
> while(auxiliar!=NULL)
> {
> printf("Nombre: %s, Telefono: %s\n",auxiliar->nom,auxiliar->tel);
> auxiliar=auxiliar->sig;
> i++;
> }
> if(i==0)
> {
> printf("\n\nLista vacia\n");
> }
> getch();
> clrscr();
> }
>
>
>
>
>
> void main()
> {
> clrscr();
> char op;
>
> primero=(struct agenda*)NULL;
> ultimo=(struct agenda*)NULL;
>
> do{mostrar_menu();op=getch();
>
> switch(op)
> {
> case '1': anadir_elemento();
> break;
>
> case '2': printf("\n No disponible....\n");
> break;
>
> case '3': mostrar_lista();
> break;
>
> case '4': exit(1);
>
> default: printf("opcion no valida\n");
> break;
> }
> }while(op!='4');
>
>
> getch();
> }
>
>
>
>
> ------------------------------
> Get news, entertainment and everything you care about at Live.com. Check
> it out! <http://www.live.com/getstarted.aspx>
>
> _______________________________________________
> Lista de correo Cconclase Cconclase en listas.conclase.net
> http://listas.conclase.net/mailman/listinfo/cconclase_listas.conclase.net
> Bajas: http://listas.conclase.net/index.php?gid=2&mnu=FAQ
>
--
(\__/)
(='.'=)This is Bunny. Copy and paste bunny into your
(")_(")signature to help him gain world domination.
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.conclase.net/pipermail/cconclase_listas.conclase.net/attachments/20100419/688d685a/attachment.html>
Más información sobre la lista de distribución Cconclase