Advertisement
Rafael09ED

Untitled

Nov 9th, 2018
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. Facility ATeam_Assignment3_1C;
  2. uses Integer_Template, Preemptable_Queue_Template;
  3.  
  4. Facility Queue_Fac is Preemptable_Queue_Template(Integer, 3)
  5. realized by Master_Circular_Array_Realiz;
  6.  
  7. Operation Read_Queue(replaces Q: P_Queue);
  8. Procedure
  9. Var I: Integer;
  10.  
  11. Clear(Q);
  12. While ( 1 <= Rem_Capacity(Q) )
  13. decreasing 3 -|Q|;
  14. do
  15. Read(I);
  16. Enqueue(I, Q);
  17. end;
  18. end Read_Queue;
  19.  
  20. Operation Write_Queue(clears Q: P_Queue);
  21. Procedure
  22. Var I: Integer;
  23.  
  24. While (Length(Q) > 0)
  25. decreasing |Q|;
  26. do
  27. Dequeue(I, Q);
  28. Write_Line(I);
  29. end;
  30.  
  31. end Write_Queue;
  32.  
  33. Operation Rotate (updates Q: P_Queue);
  34. requires 1 <= |Q|;
  35. ensures Q = Prt_Btwn(1, |#Q|, #Q) o Prt_Btwn(0, 1, #Q);
  36. Procedure
  37. Var I: Integer;
  38.  
  39. Dequeue(I, Q);
  40. Enqueue(I, Q);
  41.  
  42. end Rotate;
  43.  
  44. Operation Copy_Front (restores Q: P_Queue; replaces Front: Integer);
  45. requires 1 <= |Q|;
  46. ensures <Front> = Prt_Btwn(0, 1, Q);
  47. Procedure
  48. Var I: Integer;
  49.  
  50. Dequeue(I, Q);
  51. Front := I;
  52. Inject(I, Q);
  53.  
  54. end Copy_Front;
  55.  
  56. Operation Do_Nothing_with_Swap_Last_Entry (updates Q:P_Queue);
  57. requires |Q| >= 1;
  58. ensures #Q = Q;
  59. Procedure
  60. Var I: Integer;
  61.  
  62.  
  63. I := 1;
  64. Swap_Last_Entry(I, Q);
  65. Swap_Last_Entry(I, Q);
  66.  
  67. end Do_Nothing_with_Swap_Last_Entry;
  68. --- make proper use of the Swap_Last_Entry operation in this code
  69.  
  70. Operation Main();
  71. Procedure
  72. Var Q: P_Queue;
  73. Var I: Integer;
  74. Read_Queue(Q);
  75. Copy_Front(Q, I);
  76. Write_Line(I);
  77. Rotate(Q);
  78. Write_Queue(Q);
  79.  
  80. end Main;
  81.  
  82. end ATeam_Assignment3_1C;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement