Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <iostream>
  3. using namespace std;
  4.                                                         // IMPLEMENTACION DINAMICA
  5.  class Nodo{
  6.        int dato;
  7.        char datx;
  8.        Nodo *sig;
  9.        friend class Pila;
  10.        };
  11.  
  12.  class Pila{
  13.        Nodo *tope;
  14.        public:
  15.        //Básicas
  16.        Pila();
  17.        ~Pila();
  18.        char getDato();
  19.        int estaVacia();
  20.        void push(char x);
  21.        void pop();
  22.        // Complementarias
  23.        void Mostrar();
  24.        void invertir();
  25.        int getUltimo(); // También se le llama getFondo()
  26.        void estaOrdenada();
  27.        int Pertenece();
  28.        int getPosicion(int x);
  29.        };
  30.        
  31.        Pila::Pila(){ // BOB EL CONSTRUCTOR
  32.              tope=NULL;
  33.            }
  34.        Pila::~Pila(){ // MARTILLO EL DESTRUCTOR
  35.              Nodo *p;
  36.              p=tope;
  37.              while(p!=NULL){
  38.                  tope=tope->sig;
  39.                  delete p;
  40.                  p=tope;          
  41.                            }
  42.            }
  43.  
  44.        int Pila::estaVacia(){
  45.            return tope==NULL;
  46.            }
  47.        
  48.        char Pila::getDato(){
  49.            if(estaVacia()){
  50.                            return -1;
  51.            }
  52.            else{
  53.            return tope->dato;
  54.                   }
  55.            }
  56.        
  57.        void Pila::push(char x){
  58.            Nodo *p;
  59.            p=new Nodo();
  60.            p->dato = x;
  61.            if(estaVacia()){
  62.                 p->sig=NULL;
  63.             }
  64.             else{
  65.                 p->sig=tope;
  66.                }
  67.                tope=p;
  68.            }
  69.        
  70.        void Pila::pop(){
  71.             Nodo *p;
  72.             p=tope;
  73.             if(estaVacia()){
  74.                  cout<<"Error, lista vacia en top()";
  75.              }else{
  76.                    tope=p->sig;
  77.                    delete p;
  78.                    }
  79.             }
  80.        
  81.        void Pila::Mostrar(){
  82.             Pila px;
  83.             cout<<"Tope->";
  84.             while(!estaVacia()){
  85.                 cout<<getDato()<<"->";
  86.                 px.push(getDato());
  87.                 pop();
  88.             }
  89.             cout<<"NULL(FONDO DE LA PILA"<<endl;
  90.             while(!px.estaVacia()){
  91.                      push(px.getDato());
  92.                      px.pop();
  93.            }            
  94.        }
  95.        
  96.        void Evaluar(Pila w){
  97.             char A[3] = {'(', '{', '['};
  98.             char B[3] = {')', '}', ']'};
  99.             for(int i=0;i<3;i++){
  100.             if(w.getDato()!=A[i]){
  101.                 cout<<"ERROR!";
  102.               }
  103.             }
  104.             }
  105.        
  106.        void hu3(Pila w){
  107.             char A[3] = {'(', '{', '['};
  108.             if(w.getDato()==A[]){
  109.                 push();
  110.              }
  111.             }
  112.            
  113.  
  114.            
  115.        int main (){
  116.         Pila p;
  117.         p.push(')');
  118.         p.pop();
  119.         Evaluar(p);
  120.         p.Mostrar();
  121.         system("Pause");
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement