disiodj

CODA_DEFINIZIONI

Jan 16th, 2016
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //DEFINIZIONI CODA
  2.  
  3. CREATE-QUEUE(maxSize)
  4.     //C è una nuova coda di dimensione maxsize
  5.     c.head = -1
  6.     c.tail = -1
  7.     return c;
  8.  
  9. IS-EMPTY(c)
  10.     if(c.head == c.tail)
  11.         return TRUE
  12.     return FALSE
  13.  
  14. ENQUEUE(c, x)
  15.     if(c.head+1==c.tail || c.tail=0 && c.head==c.lenght-1)
  16.         return overflow
  17.     c[c.tail] = x
  18.     if(c.tail==c.lenght-1)
  19.         c.tail=0;
  20.     else
  21.         c.tail=c.tail+1
  22.  
  23. DEQUEUE(c)
  24.     if(c.head == c.tail)
  25.         return underflow
  26.     temp = c[c.head]
  27.     if(c.head ==0)
  28.         c.head = c.lenght-1
  29.     else
  30.         c.head = c.head+1
  31.     return temp
  32.  
  33. FRONT(C)
  34.     if(l.head==c.head)
  35.         return error underflow
  36.     return c[c.head]
  37.  
  38. EMPTY(l)
  39.     l.head==-1
  40.     l.head==l.tail
  41.     return l;
  42.  
  43. SIZE(c)
  44.     if(c.tail==c.lenght-1)
  45.         return (c.lenght-1) - c.head
  46.     if(c.tail>c.head)
  47.         return c.tail-c.head
  48.     return (c.lenght-1 - c.head)+c.tail
  49.  
  50. Tempo di esecuzione per ogni operazione: Teta(1)
Add Comment
Please, Sign In to add comment