gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
polsuma - greska u redosledu parametara
[spa1skripta-public.git] / kodovi / polinomi / polinoml-debug.mod
1 (*polinomL - debug verzija *)
2 IMPLEMENTATION MODULE PolinomL;
3 FROM InOut IMPORT Write, WriteString, WriteLn,
4 WriteCard, ReadCard, Done;
5 FROM RealInOut IMPORT WriteReal, ReadReal;
6 FROM Storage IMPORT ALLOCATE, DEALLOCATE;
8 PROCEDURE Anuliraj(VAR p: Polinom);
9 BEGIN
10 (* IF p # NIL THEN
11 DisposePolinom(p);
12 END;*)
13 p := NIL;
15 END Anuliraj;
17 PROCEDURE Kopiraj(p: Polinom; VAR kopija: Polinom);
18 VAR
19 pomocni: Polinom;
20 BEGIN
21 IF p = NIL THEN
22 kopija := NIL
23 ELSE
24 NEW(kopija);
25 kopija^ := p^;
26 p := p^.veza;
27 pomocni := kopija;
28 WHILE p <> NIL DO
29 NEW(pomocni^.veza);
30 pomocni := pomocni^.veza;
31 pomocni^ := p^;
32 p := p^.veza
33 END
34 END
35 END Kopiraj;
37 PROCEDURE Stampaj(p: Polinom; d: CARDINAL);
39 PROCEDURE StampajMonom(m : Polinom);
40 BEGIN
41 WITH m^ DO
42 IF st <> 0 THEN
43 IF ABS(k) <> 1.0 THEN
44 WriteReal(ABS(k), d)
45 END;
46 Write('x');
47 IF st <> 1 THEN
48 Write('^');
49 WriteCard(st, 1)
50 END
51 ELSE
52 WriteReal(ABS(k), d)
53 END
54 END
55 END StampajMonom;
57 BEGIN
58 IF p = NIL THEN
59 WriteReal(0., d)
60 ELSE
61 IF p^.k < 0.0 THEN
62 WriteString(' - ')
63 END;
64 StampajMonom(p);
65 p := p^.veza;
66 WHILE p <> NIL DO
67 IF p^.k > 0.0 THEN
68 WriteString(' + ')
69 ELSE
70 WriteString(' - ')
71 END;
72 StampajMonom(p);
73 p := p^.veza
74 END
75 END
76 END Stampaj;
78 PROCEDURE UbaciMonom(mon:Polinom; VAR p: Polinom);
79 VAR
80 stari, tekuci, kopija: Polinom;
81 BEGIN
82 WriteString("um ( ");
83 IF mon # NIL THEN
84 NEW(kopija);
85 kopija^ := mon^;
86 tekuci := p;
87 stari := NIL;
88 WHILE (tekuci#NIL) AND (tekuci^.st>kopija^.st) DO
89 stari := tekuci;
90 tekuci := tekuci^.veza
91 END;
92 kopija^.veza := tekuci;
93 IF tekuci = p THEN
94 p := kopija
95 ELSE
96 stari^.veza := kopija
97 END;
98 IF (tekuci#NIL) AND (kopija^.st = tekuci^.st) THEN
99 kopija^.k := kopija^.k + tekuci^.k;
100 kopija^.veza := tekuci^.veza;
101 DISPOSE(tekuci);
102 IF kopija^.k = 0.0 THEN
103 IF p = kopija THEN
104 p := kopija^.veza
105 ELSE
106 stari^.veza := kopija^.veza
107 END;
108 DISPOSE(kopija)
109 END
110 END
111 END;
112 WriteString("um ) ");
113 END UbaciMonom;
115 PROCEDURE Unos(VAR p : Polinom);
116 VAR
117 i, n: CARDINAL;
118 novi: Polinom;
119 BEGIN
120 Anuliraj(p);
121 REPEAT
122 WriteLn;
123 WriteString('Unesite broj monoma n (n>=0) ');
124 ReadCard(n);
125 UNTIL Done;
126 WriteLn;
127 FOR i := 1 TO n DO
128 NEW(novi);
129 WITH novi^ DO
130 REPEAT
131 WriteString('Unesite koeficijent monoma br.');
132 WriteCard(i, 1);
133 WriteString(' (<> 0) ');
134 ReadReal(k);
135 WriteLn
136 UNTIL k <> 0.0;
137 REPEAT
138 WriteLn;
139 WriteString('Unesite eksponent monoma br.');
140 WriteCard(i, 1);
141 WriteString(' (>=0) ');
142 ReadCard(st);
143 UNTIL Done;
144 WriteLn;
145 END;
146 UbaciMonom(novi, p);
147 DISPOSE(novi);
148 END
149 END Unos;
151 PROCEDURE Saberi(p1, p2: Polinom; VAR zbir: Polinom);
152 BEGIN
153 Kopiraj(p1, zbir);
154 WHILE p2 <> NIL DO
155 UbaciMonom(p2, zbir);
156 p2 := p2^.veza
157 END
158 END Saberi;
160 PROCEDURE SaberiNa(p: Polinom; VAR rez: Polinom);
161 BEGIN
162 WHILE p <> NIL DO
163 UbaciMonom(p,rez);
164 p := p^.veza;
165 END;
166 END SaberiNa;
168 PROCEDURE PromeniZnak(VAR p: Polinom);
169 VAR
170 t: Polinom;
171 BEGIN
172 t := p;
173 WHILE t <> NIL DO
174 t^.k := - t^.k;
175 t := t^.veza
176 END
177 END PromeniZnak;
179 PROCEDURE Oduzmi(p1,p2: Polinom; VAR razlika: Polinom);
180 BEGIN
181 Kopiraj(p2, razlika);
182 PromeniZnak(razlika);
183 WHILE p1 <> NIL DO
184 UbaciMonom(p1, razlika);
185 p1 := p1^.veza
186 END
187 END Oduzmi;
189 PROCEDURE MonomPuta(p, mon: Polinom; VAR mp: Polinom);
190 VAR
191 tekuci: Polinom;
192 BEGIN
193 WriteString("mp [ ");
194 Anuliraj(mp);
195 IF (mon <> NIL) AND (p <> NIL) THEN
196 NEW(mp);
197 mp^.k := p^.k * mon^.k;
198 mp^.st := p^.st + mon^.st;
199 p := p^.veza;
200 tekuci := mp;
201 WHILE p <> NIL DO
202 WriteString("mp w {");
203 WriteReal(p^.k,0);
204 WriteCard(p^.st,5);
205 WriteString("} ");
206 WriteLn;
207 NEW(tekuci^.veza);
208 tekuci := tekuci^.veza;
209 tekuci^.k := p^.k * mon^.k;
210 tekuci^.st := p^.st + mon^.st;
211 p := p^.veza
212 END;
213 tekuci^.veza := NIL
214 END;
215 WriteString("mp ] ");
216 END MonomPuta;
218 PROCEDURE Puta(p1, p2: Polinom; VAR pr: Polinom);
219 VAR
220 pomocni: Polinom;
221 BEGIN
222 WriteString("puta ");
223 WriteInt(p1,0);
224 Anuliraj(pr);
225 IF (p1 <> NIL) AND (p2 <> NIL) THEN
226 MonomPuta(p1, p2, pr);
227 p2 := p2^.veza;
228 WHILE p2 <> NIL DO
229 MonomPuta(p1, p2, pomocni);
230 WriteString(" puta posle mp2+ ");
231 WriteLn;
232 REPEAT
233 UbaciMonom(pomocni, pr);
234 pomocni := pomocni^.veza
235 UNTIL pomocni = NIL;
236 p2 := p2^.veza
237 END
238 END
239 END Puta;
241 PROCEDURE Kolicnik(p1, p2: Polinom; VAR kol, ost: Polinom; VAR ok: BOOLEAN);
243 PROCEDURE Deli(VAR kol, ost: Polinom);
244 VAR
245 novi, pomocni: Polinom;
246 BEGIN
247 IF ost <> NIL THEN
248 IF ost^.st >= p2^.st THEN
249 NEW(novi);
250 novi^.k := - ost^.k / p2^.k;
251 novi^.st := ost^.st - p2^.st;
252 MonomPuta(p2, novi, pomocni);
253 Saberi(ost, pomocni, ost);
254 novi^.k := - novi^.k;
255 UbaciMonom(novi, kol);
256 DISPOSE(novi);
257 Deli(kol, ost)
258 END
259 END
260 END Deli;
262 BEGIN (* Kolicnik *)
263 ok := TRUE;
264 Anuliraj(kol);
265 IF p2 = NIL THEN
266 ok := FALSE
267 ELSE
268 Kopiraj(p1, ost);
269 Deli(kol, ost)
270 END
271 END Kolicnik;
273 PROCEDURE PolinomNaN(p: Polinom; n: CARDINAL;
274 VAR rez: Polinom);
275 VAR
276 i: CARDINAL;
277 BEGIN
278 IF n = 0 THEN
279 NEW(rez);
280 rez^.k := 1.0;
281 rez^.st := 0;
282 rez^.veza := NIL;
283 ELSIF n = 1 THEN
284 Kopiraj( p, rez );
285 ELSE
286 rez := p;
287 FOR i := 2 TO n DO
288 Puta(rez, p, rez)
289 END
290 END;
291 END PolinomNaN;
293 PROCEDURE DisposePolinom(VAR p: Polinom);
294 VAR
295 pomocni: Polinom;
296 BEGIN
297 pomocni := p;
298 WHILE pomocni # NIL DO
299 p := p^.veza;
300 DISPOSE(pomocni);
301 pomocni := p
302 END
303 END DisposePolinom;
305 END PolinomL.
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner