Advertisement
Guest User

Untitled

a guest
May 30th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. Q02
  2.  
  3. Queue is:
  4. Stack s1
  5. Stack s2
  6.  
  7.  
  8. (1) Init (Queue q)
  9.  
  10. Init (q.s1)
  11. Init (q.s2)
  12.  
  13.  
  14. (2) Bool IsEmpty (Queue q)
  15.  
  16. if (IsEmpty (q.s1) && IsEmpty (q.s2))
  17. return true
  18. else
  19. return false
  20.  
  21.  
  22. (3) Enqueue (Queue q, T item)
  23.  
  24. while (!IsEmpty (q.s1))
  25. Push (q.s2, Top (q.s1))
  26. Pop (q.s1)
  27. push (q.s2, item)
  28. while (!IsEmpty (q.s2))
  29. Push (q.s1, Top (q.s2))
  30. Pop (q.s2)
  31.  
  32.  
  33. (4) Dequeue (Queue q)
  34.  
  35. Pop (s.q1)
  36.  
  37.  
  38. (5) T Front (Queue q)
  39.  
  40. Top (s.q1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement