gitweb on Svarog
projekti pod git sistemom za održavanje verzija -- projects under the git version control system
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3825a58)
raw | patch | inline | side by side (parent: 3825a58)
author | Doni Pracner <quinnuendo@gmail.com> | |
Sat, 4 May 2013 11:30:25 +0000 (13:30 +0200) | ||
committer | Doni Pracner <quinnuendo@gmail.com> | |
Sat, 4 May 2013 11:30:25 +0000 (13:30 +0200) |
kodovi/stek-redopsl/Info.def | [new file with mode: 0755] | patch | blob |
kodovi/stek-redopsl/Info.mod | [new file with mode: 0755] | patch | blob |
kodovi/stek-redopsl/RedOpsl.def | [new file with mode: 0755] | patch | blob |
kodovi/stek-redopsl/RedOpsl.mod | [new file with mode: 0755] | patch | blob |
kodovi/stek-redopsl/Stek.def | [new file with mode: 0755] | patch | blob |
kodovi/stek-redopsl/Stek.mod | [new file with mode: 0755] | patch | blob |
kodovi/stek-redopsl/procitajme.txt | [new file with mode: 0644] | patch | blob |
kodovi/stek-redopsl/stekred.mod | [new file with mode: 0755] | patch | blob |
diff --git a/kodovi/stek-redopsl/Info.def b/kodovi/stek-redopsl/Info.def
--- /dev/null
@@ -0,0 +1,4 @@
+DEFINITION MODULE Info;\r
+TYPE\r
+ InfoTip = CHAR;\r
+END Info.
\ No newline at end of file
diff --git a/kodovi/stek-redopsl/Info.mod b/kodovi/stek-redopsl/Info.mod
--- /dev/null
@@ -0,0 +1,2 @@
+IMPLEMENTATION MODULE Info;\r
+END Info.\r
diff --git a/kodovi/stek-redopsl/RedOpsl.def b/kodovi/stek-redopsl/RedOpsl.def
--- /dev/null
@@ -0,0 +1,24 @@
+DEFINITION MODULE RedOpsl;\r
+FROM Info IMPORT InfoTip;\r
+\r
+CONST\r
+ Maxred = 100;\r
+TYPE\r
+ Niz = ARRAY[1..Maxred] OF InfoTip;\r
+ RedOpslTip = RECORD\r
+ Prvi, Zadnji : CARDINAL;\r
+ Element : Niz\r
+ END;\r
+ \r
+PROCEDURE MakeNull(VAR q : RedOpslTip);\r
+PROCEDURE Empty(VAR q : RedOpslTip) : BOOLEAN;\r
+PROCEDURE First(VAR q : RedOpslTip;\r
+ VAR x : InfoTip;\r
+ VAR ok : BOOLEAN);\r
+PROCEDURE PopFirst(VAR q : RedOpslTip;\r
+ VAR ok : BOOLEAN);\r
+PROCEDURE AddRear(VAR q : RedOpslTip;\r
+ x : InfoTip;\r
+ VAR ok : BOOLEAN);\r
+\r
+END RedOpsl.\r
diff --git a/kodovi/stek-redopsl/RedOpsl.mod b/kodovi/stek-redopsl/RedOpsl.mod
--- /dev/null
@@ -0,0 +1,77 @@
+IMPLEMENTATION MODULE RedOpsl;\r
+FROM Info IMPORT InfoTip;\r
+\r
+PROCEDURE MakeNull(VAR q : RedOpslTip);\r
+BEGIN\r
+ WITH q DO\r
+ Prvi := 0;\r
+ Zadnji := 0\r
+ END\r
+END MakeNull;\r
+\r
+PROCEDURE Empty(VAR q : RedOpslTip) : BOOLEAN;\r
+BEGIN\r
+ RETURN q.Zadnji = 0\r
+END Empty;\r
+\r
+PROCEDURE First(VAR q : RedOpslTip;\r
+ VAR x : InfoTip;\r
+ VAR ok : BOOLEAN);\r
+BEGIN\r
+ IF Empty(q) THEN\r
+ ok := FALSE\r
+ ELSE\r
+ ok := TRUE;\r
+ WITH q DO\r
+ x := Element[Prvi]\r
+ END\r
+ END\r
+END First;\r
+\r
+PROCEDURE AddOne(i : CARDINAL) : CARDINAL;\r
+BEGIN\r
+ IF i = Maxred THEN\r
+ RETURN 1\r
+ ELSE\r
+ RETURN i+1\r
+ END\r
+END AddOne;\r
+\r
+PROCEDURE PopFirst(VAR q : RedOpslTip;\r
+ VAR ok : BOOLEAN);\r
+BEGIN\r
+ IF Empty(q) THEN\r
+ ok := FALSE\r
+ ELSE\r
+ ok := TRUE;\r
+ WITH q DO\r
+ IF Prvi = Zadnji THEN\r
+ MakeNull(q)\r
+ ELSE\r
+ Prvi := AddOne(Prvi)\r
+ END\r
+ END\r
+ END\r
+END PopFirst;\r
+\r
+PROCEDURE AddRear(VAR q : RedOpslTip;\r
+ x : InfoTip;\r
+ VAR ok : BOOLEAN);\r
+BEGIN\r
+ WITH q DO\r
+ IF AddOne(Zadnji) = Prvi THEN\r
+ ok := FALSE\r
+ ELSE\r
+ ok := TRUE;\r
+ IF Empty(q) THEN\r
+ Prvi := 1;\r
+ Zadnji := 1\r
+ ELSE\r
+ Zadnji := AddOne(Zadnji)\r
+ END;\r
+ Element[Zadnji] := x\r
+ END\r
+ END\r
+END AddRear;\r
+\r
+END RedOpsl.\r
diff --git a/kodovi/stek-redopsl/Stek.def b/kodovi/stek-redopsl/Stek.def
--- /dev/null
@@ -0,0 +1,25 @@
+DEFINITION MODULE Stek;\r
+FROM Info IMPORT InfoTip;\r
+\r
+CONST\r
+ Maxstek = 100;\r
+TYPE\r
+ Niz = ARRAY[1..Maxstek] OF InfoTip;\r
+ StekTip = RECORD\r
+ Top : CARDINAL;\r
+ Element : Niz\r
+ END;\r
+\r
+PROCEDURE MakeNull(VAR s : StekTip);\r
+PROCEDURE Empty(VAR s : StekTip) : BOOLEAN;\r
+\r
+PROCEDURE Top(VAR s : StekTip;\r
+ VAR x : InfoTip;\r
+ VAR ok : BOOLEAN);\r
+PROCEDURE Pop(VAR s : StekTip;\r
+ VAR ok : BOOLEAN);\r
+PROCEDURE Push(VAR s : StekTip;\r
+ x : InfoTip;\r
+ VAR ok : BOOLEAN);\r
+\r
+END Stek.\r
diff --git a/kodovi/stek-redopsl/Stek.mod b/kodovi/stek-redopsl/Stek.mod
--- /dev/null
@@ -0,0 +1,54 @@
+IMPLEMENTATION MODULE Stek;\r
+FROM Info IMPORT InfoTip;\r
+\r
+PROCEDURE MakeNull(VAR s : StekTip);\r
+BEGIN\r
+ s.Top := 0\r
+END MakeNull;\r
+\r
+PROCEDURE Empty(VAR s : StekTip) : BOOLEAN;\r
+BEGIN\r
+ RETURN s.Top = 0\r
+END Empty;\r
+\r
+PROCEDURE Top(VAR s : StekTip;\r
+ VAR x : InfoTip;\r
+ VAR ok : BOOLEAN);\r
+BEGIN\r
+ IF Empty(s) THEN\r
+ ok := FALSE\r
+ ELSE\r
+ ok := TRUE;\r
+ WITH s DO\r
+ x := Element[Top]\r
+ END\r
+ END\r
+END Top;\r
+\r
+PROCEDURE Pop(VAR s : StekTip;\r
+ VAR ok : BOOLEAN);\r
+BEGIN\r
+ IF Empty(s) THEN\r
+ ok := FALSE\r
+ ELSE\r
+ ok := TRUE;\r
+ DEC(s.Top)\r
+ END\r
+END Pop;\r
+\r
+PROCEDURE Push(VAR s : StekTip;\r
+ x : InfoTip;\r
+ VAR ok : BOOLEAN);\r
+BEGIN\r
+ WITH s DO\r
+ IF Top = Maxstek THEN\r
+ ok := FALSE\r
+ ELSE\r
+ ok := TRUE;\r
+ INC(Top);\r
+ Element[Top] := x\r
+ END\r
+ END\r
+END Push;\r
+\r
+END Stek.\r
diff --git a/kodovi/stek-redopsl/procitajme.txt b/kodovi/stek-redopsl/procitajme.txt
--- /dev/null
@@ -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
--- /dev/null
@@ -0,0 +1,52 @@
+MODULE stekred;\r
+(* prvo importujemo cele module, da bi mogli da koristimo istoimene\r
+ procedure (kao MakeNull) iz oba modula *)\r
+IMPORT RedOpsl;\r
+IMPORT Stek;\r
+(* nakon toga importujemo i sve raznoimene delove, da ne bi morali\r
+ da kucamo puna imena modula svaki put i kad ne moramo *)\r
+FROM Stek IMPORT StekTip, Top, Pop, Push;\r
+FROM RedOpsl IMPORT RedOpslTip, First, PopFirst, AddRear;\r
+FROM InOut IMPORT ReadString,WriteString,Write,WriteLn;\r
+FROM Strings IMPORT Length;\r
+\r
+VAR\r
+ str : ARRAY[1..256] OF CHAR;\r
+ q :RedOpslTip;\r
+ s :StekTip;\r
+ i : CARDINAL;\r
+ ok,palin : BOOLEAN;\r
+ c,c1 : CHAR;\r
+BEGIN\r
+ WriteString("unesite string: ");\r
+ ReadString(str);\r
+\r
+ (* inicijalizujemo strukture *)\r
+ Stek.MakeNull(s);\r
+ RedOpsl.MakeNull(q);\r
+ (* ubacujemo elemente u stek *)\r
+ FOR i:=1 TO Length(str) DO\r
+ Push(s, str[i], ok);\r
+ END;\r
+ (* ubacujemo elemente u red opsl *)\r
+ FOR i:=1 TO Length(str) DO\r
+ Push(s, str[i], ok);\r
+ END;\r
+ WriteLn;\r
+ WriteString("sadrzaj steka");\r
+ WriteLn;\r
+ WHILE NOT Stek.Empty(s) DO\r
+ Top(s,c,ok);\r
+ Pop(s,ok);\r
+ Write(c);\r
+ END;\r
+ WriteLn;\r
+ WriteString("sadrzaj reda opsl.");\r
+ WriteLn;\r
+ WHILE NOT RedOpsl.Empty(q) DO\r
+ First(q,c,ok);\r
+ PopFirst(q,ok);\r
+ Write(c);\r
+ END;\r
+ WriteLn;\r
+END stekred.
\ No newline at end of file