Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // zadatak sa vježbi red/stek
- MODULE zadatakV;
- IMPORT Stek;
- IMPORT RedOpsl;
- FROM InOut IMPORT WriteLn,WriteString,ReadString,WriteCard;
- FROM FIO IMPORT File,Open,Create,Close,EOF,RdCard,WrCard,WrLn;
- FROM Stek IMPORT StekTip,Top,Pop,Push;
- FROM RedOpsl IMPORT RedOpslTip, PopFirst,AddRear,First;
- CONST f1 = "f1.txt";
- f2 = "f2.txt";
- VAR
- str : ARRAY [1..256] OF CHAR;
- s1,s2,s3 : StekTip;
- red : RedOpslTip;
- ok : BOOLEAN;
- PROCEDURE Ucitaj(imeF:ARRAY OF CHAR; VAR red:RedOpslTip;VAR ok:BOOLEAN);
- VAR f:File;
- n:CARDINAL;
- BEGIN
- RedOpsl.MakeNull(red);
- f:=Open(imeF);
- EOF:=FALSE;
- WHILE NOT EOF DO
- n:=RdCard(f);
- AddRear(red,n,ok);
- END;
- Close(f);
- END Ucitaj;
- PROCEDURE Manje5(VAR red:RedOpslTip;VAR ok:BOOLEAN);
- VAR m:BOOLEAN;
- n:CARDINAL;
- BEGIN
- m:=TRUE;
- WHILE m AND NOT RedOpsl.Empty(red) DO
- First(red,n,ok);
- IF n < 5 THEN
- PopFirst(red,ok);
- ELSE
- m:=FALSE;
- END;
- END;
- END Manje5;
- (* PROCEDURE IspisiRed(VAR red:RedOpslTip; VAR ok:BOOLEAN);
- VAR n:CARDINAL;
- BEGIN
- WHILE NOT RedOpsl.Empty(red) DO
- First(red,n,ok);
- WriteCard(n,1);
- WriteLn;
- PopFirst(red,ok);
- END;
- END IspisiRed; *)
- PROCEDURE Sacuvaj(imeF:ARRAY OF CHAR; VAR red:RedOpslTip;VAR ok:BOOLEAN);
- VAR n:CARDINAL;
- f:File;
- BEGIN
- f:=Create(imeF);
- WHILE NOT RedOpsl.Empty(red) DO
- First(red,n,ok);
- WrCard(f,n,1);
- PopFirst(red,ok);
- WrLn(f);
- END;
- Close(f);
- END Sacuvaj;
- PROCEDURE UcitajFajlUStek(imeF:ARRAY OF CHAR;VAR stek:StekTip;VAR ok:BOOLEAN);
- VAR f:File;
- n:CARDINAL;
- BEGIN
- f:=Open(imeF);
- EOF:=FALSE;
- WHILE NOT EOF DO
- n:=RdCard(f);
- Push(stek,n,ok);
- END;
- Close(f);
- END UcitajFajlUStek;
- PROCEDURE UkloniJednocifrene(VAR stek:StekTip;VAR ok:BOOLEAN);
- VAR m:BOOLEAN;
- n:CARDINAL;
- BEGIN
- m:=TRUE;
- WHILE m AND NOT Stek.Empty(stek) DO
- Top(stek,n,ok);
- IF n<10 THEN
- Pop(stek,ok);
- ELSE
- m:=FALSE;
- END;
- END;
- END UkloniJednocifrene;
- PROCEDURE UkloniNeparne(VAR stek:StekTip;VAR ok:BOOLEAN);
- VAR m:BOOLEAN;
- n:CARDINAL;
- BEGIN
- m:=TRUE;
- WHILE m AND NOT Stek.Empty(stek) DO
- Top(stek,n,ok);
- IF ODD(n) THEN
- Pop(stek,ok);
- ELSE
- m:=FALSE;
- END;
- END;
- END UkloniNeparne;
- PROCEDURE UbaciNaizmenicno(VAR s1,s2,s3:StekTip;VAR ok:BOOLEAN);
- VAR n,m:CARDINAL;
- BEGIN
- Stek.MakeNull(s3);
- WHILE NOT Stek.Empty(s1) OR NOT Stek.Empty(s2) DO
- IF NOT Stek.Empty(s1) THEN
- Top(s1,n,ok);
- Push(s3,n,ok);
- Pop(s1,ok);
- END;
- IF NOT Stek.Empty(s2) THEN
- Top(s2,m,ok);
- Push(s3,m,ok);
- Pop(s2,ok);
- END;
- END;
- END UbaciNaizmenicno;
- (* PROCEDURE IspisiStek(stek:StekTip;VAR ok:BOOLEAN);
- VAR n:CARDINAL;
- BEGIN
- WHILE NOT Stek.Empty(stek) DO
- Top(stek,n,ok);
- WriteCard(n,1);
- WriteLn;
- Pop(stek,ok);
- END;
- END IspisiStek; *)
- PROCEDURE SacuvajStek(imeF:ARRAY OF CHAR; VAR stek:StekTip;VAR ok:BOOLEAN);
- VAR n:CARDINAL;
- f:File;
- BEGIN
- f:=Create(imeF);
- WHILE NOT Stek.Empty(stek) DO
- Top(stek,n,ok);
- WrCard(f,n,1);
- WrLn(f);
- Pop(stek,ok);
- END;
- END SacuvajStek;
- BEGIN
- Ucitaj(f1,red,ok);
- Manje5(red,ok);
- WriteString('Unesite ime fajla: ');
- ReadString(str);
- Sacuvaj(str,red,ok);
- UcitajFajlUStek(f1,s1,ok);
- UcitajFajlUStek(f2,s2,ok);
- UkloniJednocifrene(s1,ok);
- UkloniNeparne(s2,ok);
- UbaciNaizmenicno(s1,s2,s3,ok);
- WriteString('Unesite ime fajla: ');
- ReadString(str);
- SacuvajStek(str,s3,ok);
- END zadatakV.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement