Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include "Pila.h"
  2.  
  3.  
  4. namespace Mynamespace{
  5.  
  6.  
  7. bool Pila::empty()const
  8. {
  9.     if(testa == 0)
  10.         return true;
  11.        
  12.     return false;
  13. }//fine empty    
  14.  
  15.  
  16. bool Pila::push(const T & e)
  17. {
  18.     if(full())
  19.         return false;
  20.        
  21.     Nodo * q;
  22.     q = new Nodo;
  23.     q->elemento = e;
  24.     q->next = testa;
  25.     testa = q;
  26.     return true;
  27. }//fine push    
  28.  
  29.  
  30. bool Pila::pop(T & e)
  31. {
  32.     if(empty())
  33.         return false;
  34.    
  35.     Nodo * temp;
  36.     temp = testa;
  37.     e = testa->elemento;
  38.     testa = testa->next;
  39.     delete temp;
  40.     return true;
  41. }//fine pop
  42.  
  43.  
  44.  
  45. bool Pila::top(T & e)
  46. {
  47.     if(empty())
  48.         return false;
  49.        
  50.     e = testa->elemento;
  51.     return true;
  52. }//fine top
  53.  
  54.  
  55. ostream & operator<<(ostream & out, const Pila & P)
  56. {
  57.     Nodo * temp;
  58.     temp = P.testa;
  59.     while(temp)
  60.     {
  61.         cout<<temp->elemento<<" ";
  62.         temp = temp->next;
  63.     }//fine while
  64.    
  65.     return out;
  66. }//fine operator<<
  67.  
  68.  
  69.  
  70. void Pila::clear()
  71. {
  72.     Nodo * temp;
  73.     temp = testa;
  74.     while(testa)
  75.     {
  76.         testa = testa->next;
  77.         delete temp;
  78.         temp = testa;
  79.     }//fine while    
  80. }//fine clear  
  81.  
  82. }//fine namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement