Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MODULE stek;
- (*Rad nad stekovima*)
- (*Korisceni InfoTip je INTEGER, da bi se kao takav koristio, u Info.def promeniti
- char(default) u integer*)
- FROM InOut IMPORT WriteString, WriteLn, WriteInt, ReadInt;
- FROM FIO IMPORT File, Open, Create, Close, WrInt, RdInt, WrLn, EOF;
- FROM Stek IMPORT StekTip, Top, Pop, Push, MakeNull, Empty;
- CONST
- fu = "ispis.txt";
- br = "brojevi.txt"
- VAR
- f : File;
- k : INTEGER;
- s, q, w : StekTip;
- ok : BOOLEAN;
- (*iz fajla upisuje elemente u stek*)
- (*Proveriti!!! ponekad ne radi ova procedura*)
- PROCEDURE unizf(VAR s: StekTip;VAR ok: BOOLEAN);
- VAR
- f: File;
- n: INTEGER;
- BEGIN
- MakeNull(s);
- EOF := FALSE;
- ok := TRUE;
- f := Open(br);
- WHILE (NOT EOF) AND (ok) DO
- n := RdInt(f);
- Push(s,n,ok)
- END;
- Close(f);
- END unizf;
- (*ispisuje elemente iz steka u zadati fajl*)
- PROCEDURE iuf(s: StekTip);
- VAR
- f: File;
- n: INTEGER;
- ok: BOOLEAN;
- BEGIN
- f := Create(fu);
- ok := TRUE;
- WHILE (NOT Empty(s)) AND (ok) DO
- Top(s,n,ok);
- WrInt(f,n,0);
- WrLn(f);
- Pop(s,ok)
- END;
- Close(f);
- END iuf;
- (*stampanje steka*)
- PROCEDURE ispissteka(s: StekTip);
- VAR
- ok : BOOLEAN;
- n : INTEGER;
- BEGIN
- IF NOT Empty(s) THEN
- ok := TRUE;
- WHILE (NOT Empty(s)) AND ok DO
- Top(s, n, ok);
- WriteInt(n,0);
- WriteLn;
- Pop(s,ok)
- END
- ELSE
- WriteString("Nema elemenata za stampanje =====");
- WriteLn;
- END;
- END ispissteka;
- (*uklanjamo elemente iz steka, Postoji procedura MakeNull(stel) *)
- PROCEDURE ispraznistek(VAR s: StekTip);
- VAR
- ok : BOOLEAN;
- BEGIN
- WHILE NOT Empty(s) DO
- Pop(s,ok)
- END;
- END ispraznistek;
- (*od dva steka kreira se jedan novi*)
- PROCEDURE proc1(q,w: StekTip;VAR s: StekTip;VAR ok: BOOLEAN);
- VAR
- n : INTEGER;
- qem, wem : BOOLEAN;
- BEGIN
- MakeNull(s);
- qem := Empty(q);
- wem := Empty(w);
- ok := TRUE;
- WHILE (NOT qem) OR (NOT wem) DO
- IF NOT qem THEN
- Top(q,n,ok);
- IF ok THEN
- Push(s,n,ok);
- Pop(q,ok)
- END
- END;
- IF NOT wem THEN
- Top(w,n,ok);
- IF ok THEN
- Push(s,n,ok);
- Pop(w,ok)
- END
- END;
- qem := Empty(q);
- wem := Empty(w)
- END
- END proc1;
- (*od jednog steka kreairaju se dva*)
- PROCEDURE provera(s: StekTip): BOOLEAN;
- VAR
- ok : BOOLEAN;
- BEGIN
- IF NOT Empty(s) THEN
- Pop(s,ok);
- IF NOT Empty(s) THEN
- RETURN FALSE;
- END
- END;
- RETURN TRUE
- END provera;
- PROCEDURE proc2(s: StekTip;VAR q,w: StekTip);
- VAR
- turn, ok : BOOLEAN;
- n: INTEGER;
- BEGIN
- IF NOT provera(s) THEN
- MakeNull(q);
- MakeNull(w);
- turn := TRUE;
- ok := TRUE;
- WHILE (NOT Empty(s)) DO
- IF turn THEN
- Top(s,n,ok);
- IF ok THEN
- Push(q,n,ok);
- Pop(s,ok)
- END;
- turn := NOT turn
- END;
- IF NOT turn THEN
- Top(s,n,ok);
- IF ok THEN
- Push(w,n,ok);
- Pop(s,ok)
- END;
- turn := NOT turn
- END
- END
- ELSE
- IF (NOT Empty(s)) THEN
- MakeNull(q);
- Top(s,n,ok);
- Push(q,n,ok)
- ELSE
- WriteString("Pocetni stek je prazan! ")
- END
- END
- END proc2;
- (*Sa vrha steka ukloniti (neki uslov)*)
- PROCEDURE jednocifren(n: INTEGER): BOOLEAN;
- BEGIN
- IF (n DIV 10 = 0) THEN
- RETURN TRUE;
- ELSE
- RETURN FALSE;
- END
- END jednocifren;
- PROCEDURE proc3(VAR s: StekTip);
- VAR
- pr, ok : BOOLEAN;
- n : INTEGER;
- BEGIN
- IF NOT Empty(s) THEN
- pr := TRUE;
- WHILE (NOT Empty(s)) AND (pr) DO
- Top(s,n,ok);
- (*ubaciti neki drugi uslov*)
- IF (jednocifren(n)) THEN
- Pop(s,ok)
- ELSE
- pr := FALSE
- END
- END
- ELSE
- WriteString("Nema elemenata u prosledjenom steku!");
- END;
- END proc3;
- BEGIN
- MakeNull(s);
- Push(s,12,ok);
- Push(s,22,ok);
- Push(s,3,ok);
- Push(s,10,ok);
- MakeNull(q);
- Push(q,12,ok);
- Push(q,22,ok);
- Push(q,3,ok);
- Push(q,10,ok);
- MakeNull(w);
- Push(w,12,ok);
- Push(w,22,ok);
- Push(w,3,ok);
- Push(w,10,ok);
- ispissteka(s); WriteLn;
- ispissteka(q); WriteLn;
- ispissteka(w); WriteLn;
- (*ubaciti procedure za koriscenje*)
- END stek.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement