PILAS EN C++ USANDO STRUCT
/JULIO CESAR LEYVA RODRIGUEZ
//PILA CON ESTRUCTURAS
//PILA CON ESTRUCTURAS
#include <conio.h> #include <iostream.h> #include <stdio.h> #define max 5 typedef int tipodatopila; typedef struct pila { int tope; int *pila; }; //RESETEA LA PILA void resetearpila(pila *resetea) { resetea->tope=-1; gotoxy(40,6); cout<<"SE HA RESETEADO LA PILA"; } //PILA VACIA int pilavacia(pila *vacia) { if(vacia->tope==-1) { return (1); } else { return (0); } } //PILA LLENA int pilallena(pila *llena) { if(llena->tope==max-1) { return (1); } else { return (0); } } //PUSH void push(pila *push, tipodatopila dato) { (push->tope)++; *(push->pila+push->tope)=dato; } //INSERTAR EL DATO void insertareldato(pila *insertar) { tipodatopila dato; if(pilallena(insertar)==1) { gotoxy(40,6); cout<<"LA PILA ESTA LLENA"; } else { gotoxy(40,6); cout<<"INSERTE EL DATO "; cin>>dato; push(insertar,dato); } } //POP tipodatopila pop(pila *pop) { tipodatopila dato; dato=*(pop->pila+pop->tope); (pop->tope)--; return(dato); } //BORRAR void borrar(pila *borrar) { if(pilavacia(borrar)==1) { gotoxy(40,6); cout<<"LA PILA ESTA VACIA"; } else { gotoxy(40,6); cout<<"EL DATO "<<pop(borrar)<<" HA SIDO ELIMINADO"; } } //MOSTRAR PILA void mostrarpila(pila *mostrar) { if(pilavacia(mostrar)==1) { gotoxy(20,6); cout<<"NO HAY DATOS"; } else { for(int x=0; x<mostrar->tope+1; x++) { gotoxy(40,5+x); cout<<mostrar->pila[x]; } } } //MENU void menu(pila *menu) { int op; do { clrscr(); gotoxy(20,5); cout<<"MENU"; gotoxy(1,6); cout<<"1. RESETEAR PILA"; gotoxy(1,7); cout<<"2. INSERTAR DATO"; gotoxy(1,8); cout<<"3. BORRAR DATO"; gotoxy(1,9); cout<<"4. VER PILA"; gotoxy(1,10); cout<<"ELIGA UNA OPCION [ ]"; gotoxy(20,10); cin>>op; switch(op) { case 1: resetearpila(menu); gotoxy(40,7); getch(); break; case 2: insertareldato(menu); getch(); break; case 3: borrar(menu); getch(); break; case 4: mostrarpila(menu); getch(); break; } } while(op!=5); } main() { pila pilota; tipodatopila pila[max]; pilota.pila=&pila[0]; menu(&pilota); }
Comentarios
Publicar un comentario