From f760213920703c2bcdd3b9a0651e51d343acda67 Mon Sep 17 00:00:00 2001 From: Doni Pracner Date: Sat, 4 May 2013 13:30:25 +0200 Subject: [PATCH] dodati Stek i RedOpsl kodovi u repo (ne i skriptu) --- kodovi/stek-redopsl/Info.def | 4 ++ kodovi/stek-redopsl/Info.mod | 2 + kodovi/stek-redopsl/RedOpsl.def | 24 ++++++++++ kodovi/stek-redopsl/RedOpsl.mod | 77 ++++++++++++++++++++++++++++++ kodovi/stek-redopsl/Stek.def | 25 ++++++++++ kodovi/stek-redopsl/Stek.mod | 54 +++++++++++++++++++++ kodovi/stek-redopsl/procitajme.txt | 30 ++++++++++++ kodovi/stek-redopsl/stekred.mod | 52 ++++++++++++++++++++ 8 files changed, 268 insertions(+) create mode 100755 kodovi/stek-redopsl/Info.def create mode 100755 kodovi/stek-redopsl/Info.mod create mode 100755 kodovi/stek-redopsl/RedOpsl.def create mode 100755 kodovi/stek-redopsl/RedOpsl.mod create mode 100755 kodovi/stek-redopsl/Stek.def create mode 100755 kodovi/stek-redopsl/Stek.mod create mode 100644 kodovi/stek-redopsl/procitajme.txt create mode 100755 kodovi/stek-redopsl/stekred.mod diff --git a/kodovi/stek-redopsl/Info.def b/kodovi/stek-redopsl/Info.def new file mode 100755 index 0000000..7791e03 --- /dev/null +++ b/kodovi/stek-redopsl/Info.def @@ -0,0 +1,4 @@ +DEFINITION MODULE Info; +TYPE + InfoTip = CHAR; +END Info. \ No newline at end of file diff --git a/kodovi/stek-redopsl/Info.mod b/kodovi/stek-redopsl/Info.mod new file mode 100755 index 0000000..d35d4ab --- /dev/null +++ b/kodovi/stek-redopsl/Info.mod @@ -0,0 +1,2 @@ +IMPLEMENTATION MODULE Info; +END Info. diff --git a/kodovi/stek-redopsl/RedOpsl.def b/kodovi/stek-redopsl/RedOpsl.def new file mode 100755 index 0000000..94e0083 --- /dev/null +++ b/kodovi/stek-redopsl/RedOpsl.def @@ -0,0 +1,24 @@ +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. diff --git a/kodovi/stek-redopsl/RedOpsl.mod b/kodovi/stek-redopsl/RedOpsl.mod new file mode 100755 index 0000000..fc5cf09 --- /dev/null +++ b/kodovi/stek-redopsl/RedOpsl.mod @@ -0,0 +1,77 @@ +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. diff --git a/kodovi/stek-redopsl/Stek.def b/kodovi/stek-redopsl/Stek.def new file mode 100755 index 0000000..0b6a37a --- /dev/null +++ b/kodovi/stek-redopsl/Stek.def @@ -0,0 +1,25 @@ +DEFINITION MODULE Stek; +FROM Info IMPORT InfoTip; + +CONST + Maxstek = 100; +TYPE + Niz = ARRAY[1..Maxstek] OF InfoTip; + StekTip = RECORD + Top : CARDINAL; + Element : Niz + END; + +PROCEDURE MakeNull(VAR s : StekTip); +PROCEDURE Empty(VAR s : StekTip) : BOOLEAN; + +PROCEDURE Top(VAR s : StekTip; + VAR x : InfoTip; + VAR ok : BOOLEAN); +PROCEDURE Pop(VAR s : StekTip; + VAR ok : BOOLEAN); +PROCEDURE Push(VAR s : StekTip; + x : InfoTip; + VAR ok : BOOLEAN); + +END Stek. diff --git a/kodovi/stek-redopsl/Stek.mod b/kodovi/stek-redopsl/Stek.mod new file mode 100755 index 0000000..df3369c --- /dev/null +++ b/kodovi/stek-redopsl/Stek.mod @@ -0,0 +1,54 @@ +IMPLEMENTATION MODULE Stek; +FROM Info IMPORT InfoTip; + +PROCEDURE MakeNull(VAR s : StekTip); +BEGIN + s.Top := 0 +END MakeNull; + +PROCEDURE Empty(VAR s : StekTip) : BOOLEAN; +BEGIN + RETURN s.Top = 0 +END Empty; + +PROCEDURE Top(VAR s : StekTip; + VAR x : InfoTip; + VAR ok : BOOLEAN); +BEGIN + IF Empty(s) THEN + ok := FALSE + ELSE + ok := TRUE; + WITH s DO + x := Element[Top] + END + END +END Top; + +PROCEDURE Pop(VAR s : StekTip; + VAR ok : BOOLEAN); +BEGIN + IF Empty(s) THEN + ok := FALSE + ELSE + ok := TRUE; + DEC(s.Top) + END +END Pop; + +PROCEDURE Push(VAR s : StekTip; + x : InfoTip; + VAR ok : BOOLEAN); +BEGIN + WITH s DO + IF Top = Maxstek THEN + ok := FALSE + ELSE + ok := TRUE; + INC(Top); + Element[Top] := x + END + END +END Push; + +END Stek. diff --git a/kodovi/stek-redopsl/procitajme.txt b/kodovi/stek-redopsl/procitajme.txt new file mode 100644 index 0000000..113a8d4 --- /dev/null +++ b/kodovi/stek-redopsl/procitajme.txt @@ -0,0 +1,30 @@ +Moduli za rad sa stekom i redom opsluzivanja. +============================================================ + +Fajlovi: +-Stek .def i .mod implementacija steka koriscenjem niza. + +-RedOpsl .def i .mod implementacija reda opsluzivanja +koriscenjem niza. + +-Info .def i .mod definise InfoTip koji koriste prethodna +dva modula. Postavljeno na CHAR. Promena u okviru ovog +modula automatski menja sa cime rade i stek i red +opsluzivanja. + +-stekred.mod primer koriscenja oba modula odjednom. + +Da bi se koristili moduli u programu, potrebno je da +kompajler moze da pronadje odgovarajuce MOD i DEF fajlove. +Uz standardna podesavanja to ukljucuje i folder gde je i +glavni program, tj u folderu projekta. Opciono se mogu +smestiti u odgovarajuce MOD i DEF foldere u okviru projekta +koji su takodje ukljuceni u standardnu potragu za pomocnim +fajlovima. + +Verzija 2012 +-revidirana imena tipova i nekih promenljivih. + +Materijal za kurs "Strukture podataka i algoritme 1" +Katedra za racunarske nauke, DMI, PMF, UNS +http://perun.dmi.rs \ No newline at end of file diff --git a/kodovi/stek-redopsl/stekred.mod b/kodovi/stek-redopsl/stekred.mod new file mode 100755 index 0000000..ba3a3ac --- /dev/null +++ b/kodovi/stek-redopsl/stekred.mod @@ -0,0 +1,52 @@ +MODULE stekred; +(* prvo importujemo cele module, da bi mogli da koristimo istoimene + procedure (kao MakeNull) iz oba modula *) +IMPORT RedOpsl; +IMPORT Stek; +(* nakon toga importujemo i sve raznoimene delove, da ne bi morali + da kucamo puna imena modula svaki put i kad ne moramo *) +FROM Stek IMPORT StekTip, Top, Pop, Push; +FROM RedOpsl IMPORT RedOpslTip, First, PopFirst, AddRear; +FROM InOut IMPORT ReadString,WriteString,Write,WriteLn; +FROM Strings IMPORT Length; + +VAR + str : ARRAY[1..256] OF CHAR; + q :RedOpslTip; + s :StekTip; + i : CARDINAL; + ok,palin : BOOLEAN; + c,c1 : CHAR; +BEGIN + WriteString("unesite string: "); + ReadString(str); + + (* inicijalizujemo strukture *) + Stek.MakeNull(s); + RedOpsl.MakeNull(q); + (* ubacujemo elemente u stek *) + FOR i:=1 TO Length(str) DO + Push(s, str[i], ok); + END; + (* ubacujemo elemente u red opsl *) + FOR i:=1 TO Length(str) DO + Push(s, str[i], ok); + END; + WriteLn; + WriteString("sadrzaj steka"); + WriteLn; + WHILE NOT Stek.Empty(s) DO + Top(s,c,ok); + Pop(s,ok); + Write(c); + END; + WriteLn; + WriteString("sadrzaj reda opsl."); + WriteLn; + WHILE NOT RedOpsl.Empty(q) DO + First(q,c,ok); + PopFirst(q,ok); + Write(c); + END; + WriteLn; +END stekred. \ No newline at end of file -- 2.25.1