Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Pila.h"
- namespace Mynamespace{
- bool Pila::empty()const
- {
- if(testa == 0)
- return true;
- return false;
- }//fine empty
- bool Pila::push(const T & e)
- {
- if(full())
- return false;
- Nodo * q;
- q = new Nodo;
- q->elemento = e;
- q->next = testa;
- testa = q;
- return true;
- }//fine push
- bool Pila::pop(T & e)
- {
- if(empty())
- return false;
- Nodo * temp;
- temp = testa;
- e = testa->elemento;
- testa = testa->next;
- delete temp;
- return true;
- }//fine pop
- bool Pila::top(T & e)
- {
- if(empty())
- return false;
- e = testa->elemento;
- return true;
- }//fine top
- ostream & operator<<(ostream & out, const Pila & P)
- {
- Nodo * temp;
- temp = P.testa;
- while(temp)
- {
- cout<<temp->elemento<<" ";
- temp = temp->next;
- }//fine while
- return out;
- }//fine operator<<
- void Pila::clear()
- {
- Nodo * temp;
- temp = testa;
- while(testa)
- {
- testa = testa->next;
- delete temp;
- temp = testa;
- }//fine while
- }//fine clear
- }//fine namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement