Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MODULE Polinomib;
- FROM InOut IMPORT WriteString, WriteLn, WriteInt;
- FROM Storage IMPORT ALLOCATE, DEALLOCATE;
- FROM PolinomL IMPORT Polinom, UbaciMonom, Stampaj, Anuliraj;
- (*Procedure za kolokvijum iz Polinoma/SPA1*)
- (*izbacuje monome sa (k > 2.0) zameniti analogno uslov *)
- PROCEDURE izbaciuk(VAR p: Polinom);
- VAR
- tekuci, prethodni : Polinom;
- BEGIN
- WHILE (p <> NIL) AND (p^.k > 2.0) DO
- tekuci := p;
- p := p^.veza;
- DISPOSE(tekuci)
- END;
- tekuci := p;
- prethodni := NIL;
- WHILE tekuci <> NIL DO
- IF tekuci^.k > 2.0 THEN
- prethodni^.veza := tekuci^.veza;
- DISPOSE(tekuci);
- tekuci := prethodni^.veza
- ELSE
- prethodni := tekuci;
- tekuci := tekuci^.veza
- END
- END;
- WriteString('Polinom: ');
- Stampaj(p,0);
- WriteLn; WriteLn
- END izbaciuk;
- (*izbacuje monome sa parnim stepenima*)
- PROCEDURE izbaciusp(VAR p: Polinom);
- VAR
- tekuci, prethodni : Polinom;
- BEGIN
- WHILE (p <> NIL) AND (p^.st MOD 2 = 0) DO
- tekuci := p;
- p := p^.veza;
- DISPOSE(tekuci)
- END;
- tekuci := p;
- prethodni := NIL;
- WHILE tekuci <> NIL DO
- IF (tekuci^.st MOD 2 = 0) THEN
- prethodni^.veza := tekuci^.veza;
- DISPOSE(tekuci);
- tekuci := prethodni^.veza
- ELSE
- prethodni := tekuci;
- tekuci := tekuci^.veza
- END
- END;
- WriteString('Polinom beza parnih stepeni: ');
- Stampaj(p,0);
- WriteLn; WriteLn;
- END izbaciusp;
- (*izbacuje monome sa neparnim stepenima*)
- PROCEDURE izbaciusn(VAR p: Polinom);
- VAR
- tekuci, prethodni : Polinom;
- BEGIN
- WHILE (p <> NIL) AND (p^.st MOD 2 = 1) DO
- tekuci := p;
- p := p^.veza;
- DISPOSE(tekuci)
- END;
- tekuci := p;
- prethodni := NIL;
- WHILE tekuci <> NIL DO
- IF (tekuci^.st MOD 2 = 1) THEN
- prethodni^.veza := tekuci^.veza;
- DISPOSE(tekuci);
- tekuci := prethodni^.veza
- ELSE
- prethodni := tekuci;
- tekuci := tekuci^.veza
- END
- END;
- WriteString('Polinom bez neparnih stepeni: ');
- Stampaj(p,0);
- WriteLn; WriteLn;
- END izbaciusn;
- (*rasclani na parne i neparne polinome*)
- PROCEDURE napinep(p: Polinom;VAR pq, pw: Polinom);
- VAR
- temp, monom : Polinom;
- pwo, pqo : BOOLEAN;
- BEGIN
- NEW(monom);
- Anuliraj(pq);
- Anuliraj(pw);
- temp := p;
- pwo := FALSE;
- pqo := FALSE;
- WHILE temp <> NIL DO
- IF temp^.st MOD 2 = 1 THEN
- monom^.st := temp^.st;
- monom^.k := temp^.k;
- monom^.veza := NIL;
- UbaciMonom(monom,pq);
- pqo := TRUE
- ELSE
- monom^.st := temp^.st;
- monom^.k := temp^.k;
- monom^.veza := NIL;
- UbaciMonom(monom,pw);
- pwo := TRUE
- END;
- temp := temp^.veza
- END;
- DISPOSE(monom);
- IF pqo THEN
- WriteString('Polinom sa neparnim izgleda ovako: ');
- Stampaj(pq,0); WriteLn; WriteLn
- ELSE
- WriteString('Ne postoji polinom sa neparnim monomima! ');
- WriteLn; WriteLn
- END;
- IF pwo THEN
- WriteString('Polinom sa parnim izgleda ovako: ');
- Stampaj(pw,0); WriteLn; WriteLn
- ELSE
- WriteString('Ne postoji polinom sa parnim monomima! ');
- WriteLn; WriteLn
- END
- END napinep;
- (*Provera ispravnosti polinoma<?>, redosledom od 0 stepeni*)
- PROCEDURE pri(p: Polinom): BOOLEAN;
- VAR
- isp : BOOLEAN;
- temp : Polinom;
- BEGIN
- temp := p;
- isp := TRUE;
- WHILE (temp^.veza <> NIL) AND (isp) DO
- IF (temp^.st < temp^.veza^.st) THEN
- isp := FALSE
- END;
- temp := temp^.veza
- END;
- IF isp THEN
- WriteString('Polinom je ok')
- ELSE
- WriteString('Polinom je pogresno postavljen!');
- WriteLn
- END;
- RETURN isp;
- END pri;
- (*Broj Elemenata U Polinomu*)
- PROCEDURE BrEle(z: Polinom; VAR ima: BOOLEAN): INTEGER;
- VAR
- temp : Polinom;
- int: INTEGER;
- BEGIN
- temp := z;
- int := 0;
- ima := FALSE;
- WHILE temp <> NIL DO
- int := int + 1;
- temp := temp^.veza;
- ima := TRUE
- END;
- IF ima THEN
- WriteString('U polinomu ima: ');
- WriteInt(int,0);
- WriteString(' monoma.');
- WriteLn; WriteLn
- ELSE
- WriteString('U polinomu nema monoma. ');
- WriteLn; WriteLn
- END;
- RETURN int
- END BrEle;
- VAR
- monom, polinom, q, w, e: Polinom;
- o : BOOLEAN;
- int : INTEGER;
- BEGIN
- Anuliraj(polinom);
- NEW(monom);
- monom^.st := 3;
- monom^.k := 2.0;
- monom^.veza := NIL;
- UbaciMonom(monom, polinom);
- DISPOSE(monom);
- NEW(monom);
- monom^.st := 2;
- monom^.k := 5.0;
- monom^.veza := NIL;
- UbaciMonom(monom, polinom);
- DISPOSE(monom);
- NEW(monom);
- monom^.st := 1;
- monom^.k := 3.0;
- monom^.veza := NIL;
- UbaciMonom(monom, polinom);
- DISPOSE(monom);
- NEW(monom);
- monom^.st := 0;
- monom^.k := 5.0;
- monom^.veza := NIL;
- UbaciMonom(monom, polinom);
- DISPOSE(monom);
- WriteString('Polinom pre procedure: ');
- Stampaj(polinom,0);
- WriteLn; WriteLn;
- (*Ovde ubaciti proceduru*)
- (*npr
- int := BrEle(polinom,o); *)
- END Polinomib.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement