Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <iostream>
- using namespace std;
- // IMPLEMENTACION DINAMICA
- class Nodo{
- int dato;
- char datx;
- Nodo *sig;
- friend class Pila;
- };
- class Pila{
- Nodo *tope;
- public:
- //Básicas
- Pila();
- ~Pila();
- char getDato();
- int estaVacia();
- void push(char x);
- void pop();
- // Complementarias
- void Mostrar();
- void invertir();
- int getUltimo(); // También se le llama getFondo()
- void estaOrdenada();
- int Pertenece();
- int getPosicion(int x);
- };
- Pila::Pila(){ // BOB EL CONSTRUCTOR
- tope=NULL;
- }
- Pila::~Pila(){ // MARTILLO EL DESTRUCTOR
- Nodo *p;
- p=tope;
- while(p!=NULL){
- tope=tope->sig;
- delete p;
- p=tope;
- }
- }
- int Pila::estaVacia(){
- return tope==NULL;
- }
- char Pila::getDato(){
- if(estaVacia()){
- return -1;
- }
- else{
- return tope->dato;
- }
- }
- void Pila::push(char x){
- Nodo *p;
- p=new Nodo();
- p->dato = x;
- if(estaVacia()){
- p->sig=NULL;
- }
- else{
- p->sig=tope;
- }
- tope=p;
- }
- void Pila::pop(){
- Nodo *p;
- p=tope;
- if(estaVacia()){
- cout<<"Error, lista vacia en top()";
- }else{
- tope=p->sig;
- delete p;
- }
- }
- void Pila::Mostrar(){
- Pila px;
- cout<<"Tope->";
- while(!estaVacia()){
- cout<<getDato()<<"->";
- px.push(getDato());
- pop();
- }
- cout<<"NULL(FONDO DE LA PILA"<<endl;
- while(!px.estaVacia()){
- push(px.getDato());
- px.pop();
- }
- }
- void Evaluar(Pila w){
- char A[3] = {'(', '{', '['};
- char B[3] = {')', '}', ']'};
- for(int i=0;i<3;i++){
- if(w.getDato()!=A[i]){
- cout<<"ERROR!";
- }
- }
- }
- void hu3(Pila w){
- char A[3] = {'(', '{', '['};
- if(w.getDato()==A[]){
- push();
- }
- }
- int main (){
- Pila p;
- p.push(')');
- p.pop();
- Evaluar(p);
- p.Mostrar();
- system("Pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement