Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MODULE frop;
- FROM InOut IMPORT WriteString, WriteLn, WriteInt, ReadInt;
- FROM FIO IMPORT File, Open, Create, Close, WrInt, RdInt, WrLn, EOF, Exists;
- FROM RedOpsl IMPORT RedOpslTip, First,PopFirst,AddRear, MakeNull, Empty;
- (*Rad nad redom opsluzivanja, First In First Out*)
- (*Korisceni InfoTip je INTEGER, da bi se kao takav koristio, u Info.def promeniti
- char(default) u integer*)
- CONST
- upis = "upis.txt";
- unos = "upis.txt";
- (*Ucitava elemente u rop*)
- PROCEDURE dodaj(VAR r: RedOpslTip; n: INTEGER);
- VAR
- ok : BOOLEAN;
- BEGIN
- AddRear(r,n,ok);
- END dodaj;
- PROCEDURE unosur(VAR r: RedOpslTip);
- VAR
- be, n, i : INTEGER;
- BEGIN
- WriteString("Broj elemenata za unos: ");
- ReadInt(be);
- WriteString("Unos elemenata "); WriteLn;
- MakeNull(r);
- FOR i := 1 TO be DO
- WriteInt(i,2);
- WriteString(". element: ");
- ReadInt(n);
- dodaj(r,n);
- WriteLn
- END;
- END unosur;
- (*stampa elemente iz rop*)
- PROCEDURE stampajrop(r: RedOpslTip);
- VAR
- ok : BOOLEAN;
- n : INTEGER;
- BEGIN
- IF NOT Empty(r) THEN
- WriteLn;
- WriteString("Stampanje rop-a: ");
- WriteLn;
- ok := TRUE;
- WHILE (NOT Empty(r)) AND (ok) DO
- First(r,n,ok);
- IF ok THEN
- WriteInt(n,0);
- WriteString(" ");
- PopFirst(r,ok);
- END
- END
- ELSE
- WriteString("Nema elemenata u unetom rop-u. ");
- END
- END stampajrop;
- (*uklanjanje elemenata iz rop-a*)
- PROCEDURE ispraznirop(VAR r: RedOpslTip);
- VAR
- ok : BOOLEAN;
- BEGIN
- IF NOT Empty(r) THEN
- WHILE (NOT Empty(r)) DO
- PopFirst(r,ok)
- END
- END
- END ispraznirop;
- (*ispisuje elemente iz ropa u zadati fajl*)
- PROCEDURE iruf(r: RedOpslTip);
- VAR
- f : File;
- n : INTEGER;
- ok : BOOLEAN;
- BEGIN
- IF NOT Empty(r) THEN
- IF Exists(upis) THEN
- f := Open(upis)
- ELSE
- f := Create(upis)
- END;
- WHILE (NOT Empty(r)) DO
- First(r,n,ok);
- WrInt(f,n,0);
- WrLn(f);
- PopFirst(r,ok)
- END;
- Close(f);
- END;
- END iruf;
- (*iz fajla upisuje elemente u rop*)
- (*Proveriti!!! ponekad ne radi ova procedura*)
- PROCEDURE urop(VAR r: RedOpslTip);
- VAR
- ok : BOOLEAN;
- f : File;
- n : INTEGER;
- BEGIN
- IF Exists(unos) THEN
- MakeNull(r);
- EOF := FALSE;
- ok := TRUE;
- f := Open(unos);
- WHILE (NOT EOF) AND (ok) DO
- n := RdInt(f);
- AddRear(r,n,ok)
- END;
- Close(f);
- ELSE
- WriteString("Greska pri upisu, nepostojeci fajl! ")
- END
- END urop;
- (*u rop-u uklanja sa pocetka brojeve vece od svog sledbenika*)
- PROCEDURE dvaelem(r: RedOpslTip): BOOLEAN;
- BEGIN
- IF NOT Empty(r) THEN
- IF NOT Empty(r) THEN
- RETURN TRUE;
- END
- END;
- RETURN FALSE;
- END dvaelem;
- PROCEDURE sledeci(r: RedOpslTip; VAR x: INTEGER);
- VAR
- ok : BOOLEAN;
- BEGIN
- PopFirst(r,ok);
- First(r,x,ok)
- END sledeci;
- PROCEDURE ukirop(VAR r: RedOpslTip);
- VAR
- t, s : INTEGER;
- ok : BOOLEAN;
- BEGIN
- IF dvaelem(r) THEN
- ok := TRUE;
- WHILE (dvaelem(r)) AND (ok) DO
- sledeci(r,s);
- First(r,t,ok);
- IF t > s THEN
- PopFirst(r,ok)
- ELSE
- ok := FALSE
- END
- END;
- ELSE
- WriteString("Nema najmanje dva elementa. ")
- END
- END ukirop;
- (*rop podeliti na dva ropa sa parnim/neparnim brojevima*)
- PROCEDURE neparni(n: INTEGER; VAR nr: RedOpslTip; p1: BOOLEAN);
- VAR
- ok : BOOLEAN;
- BEGIN
- IF NOT p1 THEN
- MakeNull(nr)
- END;
- AddRear(nr,n,ok);
- END neparni;
- PROCEDURE parni(n: INTEGER; VAR pr: RedOpslTip; p2: BOOLEAN);
- VAR
- ok : BOOLEAN;
- BEGIN
- IF NOT p2 THEN
- MakeNull(pr)
- END;
- AddRear(pr,n,ok);
- END parni;
- PROCEDURE qonquer(r: RedOpslTip; VAR nr, pr: RedOpslTip);
- VAR
- p1, p2 : BOOLEAN;
- n : INTEGER;
- ok : BOOLEAN;
- BEGIN
- IF NOT Empty(r) THEN
- p1 := FALSE;
- p2 := FALSE;
- ok := TRUE;
- WHILE (NOT Empty(r)) AND (ok) DO
- First(r,n,ok);
- IF n MOD 2 = 1 THEN
- neparni(n,nr,p1);
- p1 := TRUE;
- ELSE
- parni(n,pr,p2);
- p2 := TRUE;
- END;
- PopFirst(r,ok);
- END
- ELSE
- WriteString("Nema elemenata u pozvanom rop-u. ")
- END
- END qonquer;
- VAR
- r1, r2, r3: RedOpslTip;
- ok : BOOLEAN;
- BEGIN
- MakeNull(r1);
- AddRear(r1,5,ok);
- AddRear(r1,5,ok);
- AddRear(r1,4,ok);
- AddRear(r1,4,ok);
- AddRear(r1,3,ok);
- qonquer(r1, r2, r3);
- WriteLn;
- WriteLn;
- stampajrop(r1);
- WriteLn;
- WriteLn;
- stampajrop(r2);
- WriteLn;
- WriteLn;
- stampajrop(r3);
- END frop.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement