Advertisement
ridjis

red_niz

Jun 22nd, 2014
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. * DEFINITION MODULE RedOpsl;
  2. FROM Info IMPORT InfoTip;
  3.  
  4. CONST
  5. Maxred = 100;
  6. TYPE
  7. Niz = ARRAY[1..Maxred] OF InfoTip;
  8. RedOpslTip = RECORD
  9. Prvi, Zadnji : CARDINAL;
  10. Element : Niz
  11. END;
  12.  
  13. PROCEDURE MakeNull(VAR q : RedOpslTip);
  14. PROCEDURE Empty(VAR q : RedOpslTip) : BOOLEAN;
  15. PROCEDURE First(VAR q : RedOpslTip;
  16. VAR x : InfoTip;
  17. VAR ok : BOOLEAN);
  18. PROCEDURE PopFirst(VAR q : RedOpslTip;
  19. VAR ok : BOOLEAN);
  20. PROCEDURE AddRear(VAR q : RedOpslTip;
  21. x : InfoTip;
  22. VAR ok : BOOLEAN);
  23.  
  24. END RedOpsl.
  25.  
  26. * IMPLEMENTATION MODULE RedOpsl;
  27. FROM Info IMPORT InfoTip;
  28.  
  29. PROCEDURE MakeNull(VAR q : RedOpslTip);
  30. BEGIN
  31. WITH q DO
  32. Prvi := 0;
  33. Zadnji := 0
  34. END
  35. END MakeNull;
  36.  
  37. PROCEDURE Empty(VAR q : RedOpslTip) : BOOLEAN;
  38. BEGIN
  39. RETURN q.Zadnji = 0
  40. END Empty;
  41.  
  42. PROCEDURE First(VAR q : RedOpslTip;
  43. VAR x : InfoTip;
  44. VAR ok : BOOLEAN);
  45. BEGIN
  46. IF Empty(q) THEN
  47. ok := FALSE
  48. ELSE
  49. ok := TRUE;
  50. WITH q DO
  51. x := Element[Prvi]
  52. END
  53. END
  54. END First;
  55.  
  56. PROCEDURE AddOne(i : CARDINAL) : CARDINAL;
  57. BEGIN
  58. IF i = Maxred THEN
  59. RETURN 1
  60. ELSE
  61. RETURN i+1
  62. END
  63. END AddOne;
  64.  
  65. PROCEDURE PopFirst(VAR q : RedOpslTip;
  66. VAR ok : BOOLEAN);
  67. BEGIN
  68. IF Empty(q) THEN
  69. ok := FALSE
  70. ELSE
  71. ok := TRUE;
  72. WITH q DO
  73. IF Prvi = Zadnji THEN
  74. MakeNull(q)
  75. ELSE
  76. Prvi := AddOne(Prvi)
  77. END
  78. END
  79. END
  80. END PopFirst;
  81.  
  82. PROCEDURE AddRear(VAR q : RedOpslTip;
  83. x : InfoTip;
  84. VAR ok : BOOLEAN);
  85. BEGIN
  86. WITH q DO
  87. IF AddOne(Zadnji) = Prvi THEN
  88. ok := FALSE
  89. ELSE
  90. ok := TRUE;
  91. IF Empty(q) THEN
  92. Prvi := 1;
  93. Zadnji := 1
  94. ELSE
  95. Zadnji := AddOne(Zadnji)
  96. END;
  97. Element[Zadnji] := x
  98. END
  99. END
  100. END AddRear;
  101.  
  102. END RedOpsl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement