Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define MaxiCola 100
- typedef struct {
- char listCola[MaxiCola];
- int fin;
- } Cola;
- void crearCola(Cola *C) {
- C->fin = -1;
- }
- int colaFull( Cola C) {
- if (C.fin == MaxiCola-1)
- return 1;
- else
- return 0;
- }
- void introducirCola(Cola *C, char elemento) {
- if (colaFull(*C) == 1) {
- printf("\nError: Desbordamiento de cola\n");
- exit(1);
- }
- C->fin++;
- C->listCola[C->fin] = elemento;
- }
- int colaPura(Cola C) {
- if (C.fin == -1)
- return 1;
- else
- return 0;
- }
- char eliminarCola(Cola *C) {
- int i;
- char aux;
- if (colaPura(*C) == 1) {
- printf("\nError: Cola Vacía\n");
- exit(1);
- }
- aux = C->listCola[0];
- for(i=0; i < C->fin; i++) {
- C->listCola[i] = C->listCola[i+1];
- }
- C->fin--;
- return aux;
- }
- void aniquilarCola(Cola *C) {
- C->fin = -1;
- }
- char proximaCola(Cola C) {
- if(colaPura(C)==1) {
- printf("Cola Vacía..");
- exit(1);
- }
- return C.listCola[0];
- }
- void exhibirCola(Cola C) {
- int i;
- if (colaPura(C) != 1) {
- printf("\nMostramos los elementos de la Cola:\n");
- for (i = 0; i <= C.fin; i++)
- {
- printf(" %c ", C.listCola[i]);
- }
- printf("\n\n");
- } else {
- printf("\nNo hay elementos en la cola... cola vacía\n");
- exit(1);
- }
- }
- //FIN colaCabecera
- #define MaxiPila 100
- typedef struct {
- char listPila[MaxiPila];
- int Cima;
- } Pila;
- void crearPila(Pila *P) {
- P->Cima = -1;
- }
- int pilaFull(Pila P){
- if (P.Cima == MaxiPila-1)
- return 1;
- else
- return 0;
- }
- void introducirPila(Pila *P, char elemento) {
- if (pilaFull(*P) == 1) {
- printf("\nError: Desbordamiento de pila\n");
- exit(1);
- }
- P->Cima++;
- P->listPila[P->Cima] = elemento;
- }
- int pilaPura(Pila P) {
- if (P.Cima == -1)
- return 1;
- else
- return 0;
- }
- char eliminarPila(Pila *P) {
- char Aux;
- if(pilaPura(*P) == 1) {
- printf("\nError: Intenta sacar elemento en pila vacía\n");
- exit(1);
- }
- Aux = P->listPila[P->Cima];
- P->Cima--;
- return Aux;
- }
- void aniquilararPila(Pila *P) {
- P->Cima = -1;
- }
- char cimaPila(Pila P) {
- if(pilaPura(P)==1) {
- printf("Pila Vacía..");
- exit(1);
- }
- return P.listPila[P.Cima];
- }
- void exhibirPila(Pila P) {
- int i;
- if (pilaPura(P) != 1) {
- printf("\nMostramos los elementos de la Pila:\n");
- for (i = 0; i <= P.Cima; i++)
- {
- printf("%c", P.listPila[i]);
- }
- printf("\n\n");
- } else {
- printf("\nNo hay elementos en la pila... pila vacía\n");
- exit(1);
- }
- }
- // FIN pilaCabecera
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement