disiodj

PILA

Jan 16th, 2016
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //DEFINIZIONI SU PILE
  2.  
  3. CREATE-STACK(Max size)
  4. //Credo un Array A di dimensione maxSize
  5. A.top ==-1
  6. return A
  7.  
  8. IS-EMPTY(p)
  9. if(p.top==-1)
  10.     return TRUE
  11. else
  12.     return FALSE
  13.  
  14. PUSH(p,x)
  15.     if(p.top==p.top[A.lenght-1])
  16.         warning overflow
  17.     p.top = p.top+1
  18.     p.A[p.top]=x
  19.  
  20. POP(p)
  21.     if(p.top==-1)
  22.         return warning underflow
  23.     temp = p.A[p.top]
  24.     p.top = p.top-1
  25.     return temp;
  26.  
  27. TOP(p)
  28.     if(p.top==-1)
  29.         return warning underflow
  30.     return p.A[p.top]
  31.  
  32. EMPTY(p)
  33.     return p.top = -1;
  34.  
  35. SIZE(p)
  36.     return p.top+1   --------------------qui stavi dimenticando il +1------------------------
  37.  
  38. Il costo di ogni operazione è Teta(1)
  39.  
  40. ____________________________________________________________________________________________________
Add Comment
Please, Sign In to add comment