[C con Clase] Pilas
Silvio S. Stenta
silviostenta en hotmail.com
Jue Abr 30 13:50:50 CEST 2009
Disculpa si entre tarde a la discucion, pero te falto poner break; despues del menu de pilas por esos pasa al menu de COLAS cuando vuelve de PILAS
Saludos. Silvio.
From: Jose Villafañe
Sent: Monday, April 27, 2009 3:50 PM
To: Lista de correo sobre C y C++
Subject: Re: [C con Clase] Pilas
tomare en cuenta lo de las variables locales, gracias!
por ahora dejo el codigo completo que hice....(es en devC++ por cierto)
#include <stdio.h>
#include <conio.h>
#include <cstdlib>
#include <iostream>
using namespace std;
void Arreglo(void);
void Pila(void);
void Cola(void);
void visualizar(void);
void insertar(void);
void extraer(void);
void visualizar1(void);
void insertar1(void);
void extraer1(void);
struct pila
{
char nombre[20];
struct pila *ant;
}*CAB=NULL,*AUX=NULL;
struct cola
{
char nombre[20];
struct cola *sig;
}*CAB1=NULL,*AUX1=NULL,*FIN1=NULL;
struct persona {
char nombre[20];
float n1, n2, n3, n4, prom;
}alumno[5];
int main()
{
char opc;
do
{
system("cls");
cout << "\t \t \t \tProyecto 2: " << endl;
cout << "\n";
cout << "1.- Arreglo" << endl;
cout << "\n";
cout << "2.- Pilas" << endl;
cout << "\n";
cout << "3.- Colas" << endl;
cout << "\n";
cout << "4.- Salir" << endl;
opc=getch( );
switch(opc)
{
case '1':
Arreglo( );
break;
case '2':
Pila( ); <<=== Falta break;
case '3':
Cola( );
}
}while (opc!='4');
}
void Arreglo(void)
{
system("cls");
for(int i=0; i<5; i++)
{
cout << "\t \t \t \tArreglos." << endl;
cout << "\n";
cout << "Nombre del Estudiante: ";
cin >> alumno[i].nombre;
cout << "\n";
cout << "Nota 1: ";
cin >> alumno[i].n1;
cout <<"\n";
cout << "Nota 2: ";
cin >> alumno[i].n2;
cout << "\n";
cout << "Nota 3: ";
cin >> alumno[i].n3;
cout << "\n";
cout << "Nota 4: ";
cin >> alumno[i].n4;
cout << "\n";
alumno[i].prom= (alumno[i].n1 + alumno[i].n2 + alumno[i].n3 + alumno[i].n4)/4;
cout << "Promedio: " << alumno[i].prom << endl;
cout << "\n";
system("pause");
cout << "\n";
}
}
void Pila(void)
{
char opc;
do
{
system("cls");
cout << "\t \t \t \tPila." << endl;
cout << "\n";
cout << "1.- Insertar" << endl;
cout << "\n";
cout << "2.- Extraer" << endl;
cout << "\n";
cout << "3.- Visualizar la pila" << endl;
cout << "\n";
cout << "4.- Salir" << endl;
opc=getch( );
switch(opc)
{
case '1':
insertar( );
break;
case '2':
extraer( );
break;
case '3':
visualizar( );
}
}while (opc!='4');
}
void insertar(void)
{
AUX=(struct pila *)malloc(sizeof(struct pila));
system("cls");
cout << "Nombre: ";
gets(AUX->nombre);
if (CAB==NULL)
{
CAB=AUX;
AUX->ant=NULL;
}
else
{
AUX->ant=CAB;
CAB=AUX;
}
}
void extraer(void)
{
if (CAB==NULL) return;
AUX=CAB;
CAB=CAB->ant;
free(AUX);
}
void visualizar(void)
{
if (CAB==NULL) return;
system("cls");
AUX=CAB;
while (AUX!=NULL)
{
cout << "Nombre: " << AUX->nombre << endl;
AUX=AUX->ant;
}
getch( );
}
void Cola(void)
{
char opc;
do
{
system("cls");
cout << "\t \t \t \tColas." << endl;
cout << "\n";
cout << "1.- Insertar" << endl;
cout << "\n";
cout << "2.- Extraer" << endl;
cout << "\n";
cout << "3.- Visualizar la cola" << endl;
cout << "\n";
cout << "4.- Salir" << endl;
opc=getch( );
switch(opc)
{
case '1':
insertar1( );
break;
case '2':
extraer1( );
break;
case '3':
visualizar1( );
}
}while (opc!='4');
}
void insertar1(void)
{
AUX1=(struct cola *)malloc(sizeof(struct cola));
system("cls");
cout << "Nombre: ";
gets(AUX1->nombre);
AUX1->sig=NULL;
if (FIN1==NULL)
FIN1=CAB1=AUX1;
else
{
FIN1->sig=AUX1;
FIN1=AUX1;
}
}
void extraer1(void)
{
if (CAB1==NULL) return;
AUX1=CAB1;
CAB1=CAB1->sig;
free(AUX1);
}
void visualizar1(void)
{
if (CAB1==NULL) return;
system("cls");
AUX1=CAB1;
while (AUX1!=NULL)
{
cout << "Nombre: " << AUX1->nombre << endl;
AUX1=AUX1->sig;
}
getch();
}
_______________________________________________
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
--------------------------------------------------------------------------------
_______________________________________________
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
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.conclase.net/pipermail/cconclase_listas.conclase.net/attachments/20090430/e9b03969/attachment.html>
Más información sobre la lista de distribución Cconclase