Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- * DEFINITION MODULE RedOpsl;
- FROM Info IMPORT InfoTip;
- CONST
- Maxred = 100;
- TYPE
- Niz = ARRAY[1..Maxred] OF InfoTip;
- RedOpslTip = RECORD
- Prvi, Zadnji : CARDINAL;
- Element : Niz
- END;
- PROCEDURE MakeNull(VAR q : RedOpslTip);
- PROCEDURE Empty(VAR q : RedOpslTip) : BOOLEAN;
- PROCEDURE First(VAR q : RedOpslTip;
- VAR x : InfoTip;
- VAR ok : BOOLEAN);
- PROCEDURE PopFirst(VAR q : RedOpslTip;
- VAR ok : BOOLEAN);
- PROCEDURE AddRear(VAR q : RedOpslTip;
- x : InfoTip;
- VAR ok : BOOLEAN);
- END RedOpsl.
- * IMPLEMENTATION MODULE RedOpsl;
- FROM Info IMPORT InfoTip;
- PROCEDURE MakeNull(VAR q : RedOpslTip);
- BEGIN
- WITH q DO
- Prvi := 0;
- Zadnji := 0
- END
- END MakeNull;
- PROCEDURE Empty(VAR q : RedOpslTip) : BOOLEAN;
- BEGIN
- RETURN q.Zadnji = 0
- END Empty;
- PROCEDURE First(VAR q : RedOpslTip;
- VAR x : InfoTip;
- VAR ok : BOOLEAN);
- BEGIN
- IF Empty(q) THEN
- ok := FALSE
- ELSE
- ok := TRUE;
- WITH q DO
- x := Element[Prvi]
- END
- END
- END First;
- PROCEDURE AddOne(i : CARDINAL) : CARDINAL;
- BEGIN
- IF i = Maxred THEN
- RETURN 1
- ELSE
- RETURN i+1
- END
- END AddOne;
- PROCEDURE PopFirst(VAR q : RedOpslTip;
- VAR ok : BOOLEAN);
- BEGIN
- IF Empty(q) THEN
- ok := FALSE
- ELSE
- ok := TRUE;
- WITH q DO
- IF Prvi = Zadnji THEN
- MakeNull(q)
- ELSE
- Prvi := AddOne(Prvi)
- END
- END
- END
- END PopFirst;
- PROCEDURE AddRear(VAR q : RedOpslTip;
- x : InfoTip;
- VAR ok : BOOLEAN);
- BEGIN
- WITH q DO
- IF AddOne(Zadnji) = Prvi THEN
- ok := FALSE
- ELSE
- ok := TRUE;
- IF Empty(q) THEN
- Prvi := 1;
- Zadnji := 1
- ELSE
- Zadnji := AddOne(Zadnji)
- END;
- Element[Zadnji] := x
- END
- END
- END AddRear;
- END RedOpsl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement