You are on page 1of 5

1: /*

2: INSTITUTO POLITÉCNICO NACIONAL


3: ESCUELA SUPERIOR DE CÓMPUTO
4: ESTRUCTURAS DE DATOS
5: GRUPO:
6: ALUMNOS:
7:
8:
9: PROFESOR: BENJAMÍN LUNA BENOSO
10: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
/*
INSTITUTOPOLITÉCNICONACIONAL
ESCUELASUPERIORDECÓMPUTO
ESTRUCTURASDEDATOS
GRUPO:
ALUMNOS: _____________
PROFESOR:BENJAMÍNLUNABENOSO
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
ARCHIVO DE CABECERA PARA LA DEFINICIÓN DEL TAD PILA
FECHA:
*/

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

#define TAMMAX 100

//Definición del TAD PILA


typedef struct pila
{
TipoDato listaPila[TAMMAX];
int cima;
}PILA;
//Operaciones fundamentales del TAD PILA
void CrearPila(PILA *P);
void InsertarPila(PILA *P, TipoDato elemento);
TipoDato QuitarPila(PILA *P);
void LimpiarPila(PILA *P);
TipoDato CimaPila(PILA P);
Int PilaLlena(PILA P);
int PilaVacia(PILA P);
1: /*
2: INSTITUTO POLITÉCNICO NACIONAL
3: ESCUELA SUPERIOR DE CÓMPUTO
4: ESTRUCTURAS DE DATOS
5: GRUPO:
6: ALUMNOS:
7:
8:
9: PROFESOR: BENJAMÍN LUNA BENOSO
10: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

16: //definición del tipo de dato genérico


17: typedef char TipoDato;
18:
19: #include "PILA.h"
20:
21: //función que inicializa el valor de cima en -1
22: void CrearPila(PILA *P)
23: {
24: P->cima=-1;
25: }
26:
27: //función para ingresar elementos en una pila
28: void InsertarPila(PILA *P, TipoDato elemento)
29: {
30: if(PilaLlena(*P)==1)
31: {
32: puts("Error, Pila Llena");
33: system("PAUSE");
34: exit(-1);
35: }
36: P->cima++;
37: P->listaPila[P->cima]=elemento;
38: }
39:
40: //función para sacar los elementos de una pila
41: TipoDato QuitarPila(PILA *P)
42: {
43: TipoDato aux;
44: if(PilaVacia(*P)==1)
45: {
46: puts("Error, Pila Vacia");
47: system("PAUSE");
48: exit(-1);
49: }
50: aux=P->listaPila[P->cima];
51: P->cima--;
52: return aux;
53: }
54:
55: //función que devuelve el valor de cima a -1
56: void LimpiarPila(PILA *P)
57: {
58: P->cima=-1;
59: }
60:
61: //función que lee el elemento de la cima de la pila sin eliminarlo
62: TipoDato CimaPila(PILA P)
63: {
64: return (P.listaPila[P.cima]);
65: }
66:
67: //función que comprueba si una pila se encuentra llena
68: int PilaLlena(PILA P)
69: {
70: if(P.cima==TAMMAX-1)
71: return 1;
72: return 0;
73: }
74:
75: //función que comprueba si una pila se encuentra vacía
76: int PilaVacia(PILA P)
77: {
78: if(P.cima==-1)
79: return 1;
80: return 0;
81: }
82:
1: /*
2: INSTITUTO POLITÉCNICO NACIONAL
3: ESCUELA SUPERIOR DE CÓMPUTO
4: ESTRUCTURAS DE DATOS
5: GRUPO:
6: ALUMNOS:
7:
8:
9: PROFESOR: BENJAMÍN LUNA BENOSO
10: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
11: PRÁCTICA NUMERO:
12: TITULO: PALÍNDROMO MEDIANTE EL USO DE PILAS
13: DESARROLLO: IMPLEMENTAR UN PROGRAMA QUE MUESTRE SI UNA PALABRA
14: INGRESADA POR EL USUARIO ES O NO UN PALÍNDROMO.
15:
16: FECHA:
17: */
18: #include "PILA.cpp"
19:
20: void palindromo();
21: void menu();
22:
23: // Como pueden observar, en el main solo va la llamada a una función
24:
25: main()
26: {
27:
28: menu();
29: system("PAUSE");
30: return 0;
31: }
32:
33:
34: void palindromo()
35: {
36:
37: PILA A,B,C;
38: char car;
39: int bandera=1; // se incializa a 1 suponiendo que la cadena es un palíndromo
40: TipoDato r1, r2;
41:
42: CrearPila(&A);
43: CrearPila(&B);
44: CrearPila(&C);
45:
46:
47: // se ingresan los elementos a la pila A y B al mismo tiempo
48: while((car=getchar())!='\n')
49: {
50:
51: InsertarPila(&A,car);
52: InsertarPila(&B,car);
53: }
54: // Se sacan los elementos de la pila B y se pasan a la pila C
55: while(!PilaVacia(B))
56: {
57: r1=QuitarPila(&B);
58: InsertarPila(&C,r1);
59: }
60:
61: //se comparan los elementos de la pila A y C
62: while(!PilaVacia(A))
63: {
64: r1=QuitarPila(&A);
65: r2=QuitarPila(&C);
66: if(r1!=r2)
67: {
68: bandera=0;
69: break;
70: }
71: }
72:
73: bandera==1?puts("Si es palindromo"):puts("No es palindromo");
74:
75: }
76:
77:
78: void menu()
79: {
80: char car;
81:
82: do{
83: system("CLS");
84: puts(" ------------------------------------------------------------------------ ");
85: printf("Instrucciones:\n");
86: printf("Dado un texto ingresado por el usuario, este programa muestra si el texto es u
87: puts(" ------------------------------------------------------------------------ ");
88: puts("Menu:");
89: puts("1. Ingresar palabra");
90: puts("2. Salir");
91: fflush(stdin);
92: scanf("%c", &car);
93: }while(car!='1' && car!='2');
94:
95: switch(car)
96: {
97: case '1':
98: fflush(stdin);
99: palindromo();
100: fflush(stdin);
101: break;
102: case '2':
103: exit(0);
104: }
105: }
106:

You might also like