elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
28 Mayo 2012, 21:43  


Tema destacado: Últimos eventos sobre seguridad/inseguridad

+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General (Moderador: Littlehorse)
| | |-+  Duda con Cola Circular???
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Duda con Cola Circular???  (Leído 313 veces)
buentipo_cc

Desconectado Desconectado

Mensajes: 94


¡Amo YaBB SE!


Ver Perfil
Duda con Cola Circular???
« en: 12 Octubre 2004, 16:19 »

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;

     }

}
    }


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;

     }

}
    }

Asi quedaria?????

Espero su ayuda ya que tengo prueba de esto en unos dias :P

Salu2!


En línea
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[RETO] Matriz de Cuenta Circular 7913 « 1 2 »
Programación Visual Basic
79137913 15 1,793 Último mensaje 13 Enero 2011, 15:30
por 79137913
Convolución Circular
Programación C/C++
drbeat 5 1,324 Último mensaje 2 Marzo 2011, 15:57
por drbeat
ayuda en cola
Programación C/C++
josue_tux 0 192 Último mensaje 26 Junio 2011, 06:47
por josue_tux
Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines