From bf039344cdd8d67a049f821bd68a6edc74504126 Mon Sep 17 00:00:00 2001 From: Doni Pracner Date: Wed, 5 Feb 2014 22:52:28 +0100 Subject: [PATCH] PolinomL - ver 2014 - dodata procedura za postavljanje clana, prepravljen primer koji formira polinom da koristi ovo --- kodovi/polinomi/POLINOML.DEF | 4 ++- kodovi/polinomi/POLINOML.MOD | 47 +++++++++++++++++++++++++++++++++++- kodovi/polinomi/polinom.MOD | 31 ++++++------------------ 3 files changed, 56 insertions(+), 26 deletions(-) diff --git a/kodovi/polinomi/POLINOML.DEF b/kodovi/polinomi/POLINOML.DEF index 5b50bc1..a88e55b 100644 --- a/kodovi/polinomi/POLINOML.DEF +++ b/kodovi/polinomi/POLINOML.DEF @@ -1,5 +1,5 @@ (* Modul za rad sa polinomima preko listi - verzija 2012, rev 1 *) + verzija 2014 *) DEFINITION MODULE PolinomL; TYPE Polinom = POINTER TO Monom; @@ -14,6 +14,8 @@ PROCEDURE Unos(VAR p: Polinom); PROCEDURE Stampaj(p: Polinom; d: CARDINAL); PROCEDURE Kopiraj(p: Polinom; VAR kopija: Polinom); +PROCEDURE PostaviClan(k: REAL; st:CARDINAL; + VAR p:Polinom); PROCEDURE UbaciMonom(mon:Polinom; VAR p: Polinom); PROCEDURE PromeniZnak(VAR p: Polinom); diff --git a/kodovi/polinomi/POLINOML.MOD b/kodovi/polinomi/POLINOML.MOD index 405e485..3781d25 100644 --- a/kodovi/polinomi/POLINOML.MOD +++ b/kodovi/polinomi/POLINOML.MOD @@ -1,5 +1,5 @@ (* Modul za rad sa polinomima preko listi - verzija 2012, rev 1 *) + verzija 2014 *) IMPLEMENTATION MODULE PolinomL; FROM InOut IMPORT Write, WriteString, WriteLn, WriteCard, ReadCard, Done; @@ -72,6 +72,51 @@ BEGIN END END Stampaj; +PROCEDURE PostaviClan(k:REAL; st:CARDINAL; + VAR p:Polinom); +VAR + cilj, prethodni : Polinom; +BEGIN + cilj := p; + prethodni := NIL; + WHILE (cilj # NIL) AND (cilj^.st>st) DO + prethodni := cilj; + cilj := cilj^.veza; + END; + IF (cilj = NIL) THEN + IF k#0.0 THEN + NEW(cilj); + cilj^.k := k; + cilj^.st := st; + cilj^.veza := NIL; + IF (p = NIL) THEN + p := cilj; + ELSE + prethodni^.veza := cilj; + END; + END; + ELSIF cilj^.st=st THEN + IF k#0.0 THEN + cilj^.k:=k; + ELSE + IF (p=cilj) THEN + DISPOSE(p); + ELSE + prethodni^.veza:= prethodni^.veza^.veza; + DISPOSE(cilj); + END; + END; + ELSE + IF k#0.0 THEN + NEW(cilj); + cilj^.k := k; + cilj^.st := st; + cilj^.veza := prethodni^.veza; + prethodni^.veza := cilj; + END; + END; +END PostaviClan; + PROCEDURE UbaciMonom(mon:Polinom; VAR p: Polinom); VAR stari, tekuci, kopija: Polinom; diff --git a/kodovi/polinomi/polinom.MOD b/kodovi/polinomi/polinom.MOD index 3e46e54..923e897 100644 --- a/kodovi/polinomi/polinom.MOD +++ b/kodovi/polinomi/polinom.MOD @@ -1,11 +1,11 @@ MODULE polinom; FROM PolinomL IMPORT Polinom, Stampaj, Anuliraj, - DisposePolinom, UbaciMonom, Unos, Saberi; + DisposePolinom, PostaviClan, Unos, Saberi; FROM InOut IMPORT WriteString, WriteLn; FROM Storage IMPORT ALLOCATE, DEALLOCATE; VAR - p,q,rez,pom : Polinom; + p,q,rez : Polinom; BEGIN (* korisnik unosi prvi polinom *) @@ -15,31 +15,14 @@ BEGIN (* drugi polinom kreiramo mi, monom po monom *) Anuliraj(q); (* isto sto i q:=NIL; *) - (* formiramo monom x^5 *) - NEW(pom); - pom^.st:=5; - pom^.k:=1.0; - (* dodajemo ga u polinom *) - UbaciMonom(pom,q); - DISPOSE(pom); + (* postavimo clan x^5 *) + PostaviClan(1.0,5,q); (* -3 x^4 *) - NEW(pom); - pom^.st := 4; - pom^.k := -3.0; - UbaciMonom(pom,q); - DISPOSE(pom); + PostaviClan(-3.0,4,q); (* 4 x *) - NEW(pom); - pom^.st := 1; - pom^.k := 4.0; - UbaciMonom(pom,q); - DISPOSE(pom); + PostaviClan(4.0,1,q); (* 7 (x^0) *) - NEW(pom); - pom^.st := 0; - pom^.k := 7.0; - UbaciMonom(pom,q); - DISPOSE(pom); + PostaviClan(7.0,0,q); (* saberemo polinome *) Saberi(p, q, rez); (* odstampamo rezultat i polinome *) -- 2.25.1