C/Visual C - programa dudas codigo

 
Vista:

programa dudas codigo

Publicado por paula ulloa (1 intervención) el 12/05/2007 02:42:55
HOLA BUENAS TARDES, TENGO UNAS DUDAS QUE NO LAS ENTIENDO Y ME GUSTARIAN QUE ME AYUDARAN,
LAS DUDAS LAS TENGO MARCADAS MAS ABAJO CON * Y /

//tambien otras dudas: 1.-tengo que ingresar 10 numeros, y cada dos numeros sumar y guardarlos en en la misma pila
2.-
1.-desntro este ejercio como puedo hacer

#include <conio.h>
#include <stdio.h>
#include <stdlib.h>

#define TRUE 1
#define FALSE 0

struct Nodo
{
int Dato;
struct Nodo * Siguiente;
}
;

struct Nodo * Tope;

void Inicio( void )
{
Tope = NULL;
return;
}

struct Nodo * CreaEspacio( void )
{
return ( ( struct Nodo * ) malloc( sizeof ( struct Nodo ) ) );
}

int Empty()
{
if ( Tope == NULL )
return TRUE;
else
return FALSE;
}

void Push( int X )
{
struct Nodo * Nuevo;
Nuevo = CreaEspacio();
Nuevo -> Dato = X;
if ( Empty() )
{
Nuevo -> Siguiente = NULL;
Tope = Nuevo;
}
else
{
Nuevo -> Siguiente = Tope;
Tope = Nuevo;
}
return;
}

int Pop( void )
{
struct Nodo * Q;
int X;
if ( Empty() )
{
printf( "Pila vac¡a.\n" );
getch();
fflush( stdin );
X=0;
}
else
{
Q = Tope -> Siguiente;
X = Tope -> Dato;
free( Tope );
Tope = Q;
}
return X;
}

void Mostrar( struct Nodo * P )
{
while ( P != NULL )
{
printf( "\n%d", P -> Dato );
if ( P == Tope )
printf( "<- Tope." );
P = P -> Siguiente;
}
printf( "\n" );
return;
}

////////////////////////////******************//////////////////////////
AQUI NO SE PORQUE NO ME MUESTRA LOS CINCO DATOS DE UNA PILA.
//////////////////////////////////////////////////////////////
void elem5( struct Nodo * P )
{
int i;
while ( P != NULL )
{
for(i=1; i>=5; i++)
printf( "\n%d", P -> Dato );
if ( P == Tope )
printf( "<- Tope." );
P = P -> Siguiente;

}
printf( "\n" );
return;
}

////////////////////////////******************//////////////////////////
//////////////////////////////////////////////////////////////
void LiberarEspacio( struct Nodo * P )
{
while ( P -> Siguiente != NULL )
{
LiberarEspacio( P -> Siguiente );
P -> Siguiente = NULL;
}
free( P );
return;
}

int main( void )
{
char Opcion;
int j, Salir;
Salir = 0;
Inicio();
do
{
clrscr();
gotoxy( 10, 10 );
printf("[1] Push.");

gotoxy( 10, 12 );
printf("[2] Pop.");

////////////////////////////******************//////////////////////////
//////////////////////////////////////////////////////////////
QUE SIGNIFICA ESTO
gotoxy( 10, 14 );

////////////////////////////******************//////////////////////////
//////////////////////////////////////////////////////////////
printf("[3] Mostrar. ");
gotoxy( 10, 16 );
printf("[4] Liberar.");
gotoxy( 10, 18 );
printf("[5] Mostrar Primeros 5 elementos!.");
gotoxy( 10, 20 );
printf("[6] Salir.");
Opcion = getch();
fflush( stdin );
switch ( Opcion )
{
case '1' :
clrscr();
printf( "Ingrese un valor: " );
scanf( "%d", & j );
Push( j );
break;
case '2' :
clrscr();
printf( "Valor extraido: %d\n", Pop() );
printf( "Presione una tecla para continuar.");
getch();
fflush( stdin );
break;
case '3' :
clrscr();
Mostrar( Tope );
printf( "Presione una tecla para continuar.");
getch();
fflush( stdin );
break;
case '4' :
LiberarEspacio( Tope );
Inicio();
clrscr();
printf( "Espacio liberado.\n");
printf( "Presione una tecla para continuar.");
getch();
fflush( stdin );
break;
case '5' :
/*LiberarEspacio( Tope );
Inicio();*/
clrscr();
elem5(Tope);
/*printf( "Espacio liberado.\n");*/
printf( "Presione una tecla para continuar.");
getch();
fflush( stdin );
break;
case '6' :
Salir = 1;
break;
}
}
while( ! Salir );
return 0;
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder