Buscar

pilha.h

Esta é uma pré-visualização de arquivo. Entre para ver o arquivo original

#ifndef PILHA_H_INCLUDED
#define PILHA_H_INCLUDED
#define MAX 50
struct Pilha
{
 int elementos[MAX];
 int topo;
 Pilha();
 void empilha(int x);
 int desempilha();
 int elementoDoTopo();
 bool pilhaCheia();
 bool pilhaVazia();
 int getTopo();
 int getValor(int posicao);
};
Pilha::Pilha()
{
 topo=-1;
}
void Pilha::empilha(int x)
{
 topo++;
 elementos[topo]=x;
}
int Pilha::desempilha()
{
 int t=elementos[topo];
 topo--;
 return t;
}
int Pilha::elementoDoTopo()
{
 return elementos[topo];
}
bool Pilha::pilhaCheia()
{
 return topo == MAX-1;
}
bool Pilha::pilhaVazia()
{
 return topo == -1;
}
int Pilha::getTopo()
{
 return topo;
}
int Pilha::getValor(int posicao)
{
 return elementos[posicao];
}
#endif // PILHA_H_INCLUDED

Teste o Premium para desbloquear

Aproveite todos os benefícios por 3 dias sem pagar! 😉
Já tem cadastro?

Continue navegando