Guest User

Untitled

a guest
Mar 17th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.45 KB | None | 0 0
  1. /* Andrés Partida Álvarez
  2.    Nombre De la practica: "Pila Dinamica"
  3.    Fecha: 18/11/11
  4.    Sección: D04
  5. */
  6.  
  7. # include <stdio.h>
  8. # include <stdlib.h>
  9.  
  10. # include "Funciones_7_pil_din.h"
  11.  
  12. int main()
  13. {
  14.     char resp;
  15.     int dato;
  16.     Pila *P;
  17.     inicializar(P);
  18.     do
  19.     {
  20.         system("cls");
  21.         printf("\t\t*** Pilas Dinamicas Basadas en LSLLSE ***\n");
  22.         printf("\t\t\t*** MENU ***\nA).- Apilar\nD).- Desapilar\nI).- Inicializar(anular)\nM).- Mostrar\nT).- Tope\nS).- salir\n>>> ");
  23.         fflush(stdin);
  24.         scanf("%c",&resp);
  25.         resp = toupper(resp);
  26.         switch (resp)
  27.         {
  28.             case 'A': //system("cls");
  29.                       printf("Escriba el numero a APILAR\n");
  30.                       scanf("%i",&dato);
  31.                       apilar(&dato, P);
  32.                       printf("Dato apilado\n");
  33.             break;
  34.  
  35.             case 'D': //system("cls");
  36.                       if (vacia(P))
  37.                         printf("La Pila esta vacia\n");
  38.                       else
  39.                       {
  40.                           desapilar(P);
  41.                           printf("Elemento desapilado\n");
  42.                       }
  43.  
  44.             break;
  45.  
  46.             case 'I': //system("cls");
  47.                       inicializar(P);
  48.                       printf("La pila ha sido inicializada\n");
  49.             break;
  50.  
  51.             case 'M': //system("cls");
  52.                       if(vacia(P))
  53.                       {
  54.                           printf("\t\t*** LISTA VACIA ***\n");
  55.                       }
  56.                       else
  57.                           printf("Elementos apilados...\n");
  58.                           mostrarPila(P);
  59.             break;
  60.  
  61.             /*case 'T':
  62.                       if (vacia(P))
  63.                         printf("La pila esta vacia\n");
  64.                       else
  65.                         printf("Elemento del tope es:\n");
  66.                         printf("%i",tope(&P)->elem);
  67.             break;*/
  68.  
  69.             case 'S': printf("\t\t*** FIN DEL PROGRAMA ***\a\a\n");
  70.             break;
  71.  
  72.             default : printf("\t\tOpcion No valida\a\a\n");
  73.             break;
  74.         }
  75.         system("pause");
  76.     }while (resp != 'S');
  77.  
  78.     return 0;
  79. }
  80. ////////////////////////////////////////////////////////////////////////////////////////////
  81.  
  82.  
  83. #ifndef FUNCIONES_7_PIL_DIN_H_INCLUDED
  84. #define FUNCIONES_7_PIL_DIN_H_INCLUDED
  85.  
  86. typedef struct Nodo
  87. {
  88.     int elem;
  89.     struct Nodo *sig;
  90. }Nodo;
  91.  
  92. typedef Nodo *pos;
  93. typedef Nodo *Pila;
  94.  
  95. void inicializar(Pila *P)
  96. {
  97.     *P = NULL;
  98. }
  99.  
  100. pos recevaNodo()
  101. {
  102.     Nodo * aux;
  103.     aux = (Nodo*)malloc(sizeof(Nodo));
  104.     return aux;
  105. }
  106.  
  107. int vacia(Pila *P)
  108. {
  109.     if (*P == NULL)
  110.         return 1;
  111.     else
  112.         return 0;
  113. }
  114.  
  115. void apilar(int *x, Pila *P)
  116. {
  117.     pos aux;
  118.     aux = recevaNodo();
  119.     if (aux)
  120.     {
  121.         aux->elem = *x;
  122.         aux->sig = *P;
  123.         *P = aux;
  124.     }
  125. }
  126.  
  127. void desapilar(Pila *P)
  128. {
  129.     Nodo *aux;
  130.     aux = *P;
  131.     *P= aux->sig;
  132.     free(aux);
  133. }
  134.  
  135. void mostrarPila(Pila *P)
  136. {
  137.     Nodo *aux;
  138.     aux = *P;
  139.     while (aux != NULL )
  140.         {
  141.             printf("%i\n",aux->elem);
  142.             aux = aux->sig;
  143.         }
  144. }
  145.  
  146.  
  147. /*pos tope(Pila *P)
  148. {
  149.     pos aux;
  150.     aux = *P;
  151.     if (!vacia(P))
  152.     {
  153.         while (aux != NULL)
  154.             aux = aux->sig;
  155.             return &aux;
  156.     }
  157.     else
  158.         return 0;
  159. }*/
  160. #endif // FUNCIONES_7_PIL_DIN_H_INCLUDED
Add Comment
Please, Sign In to add comment