Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MODULE Polinomija;
- FROM InOut IMPORT WriteString, WriteLn, WriteInt, ReadInt;
- FROM Storage IMPORT ALLOCATE, DEALLOCATE;
- FROM PolinomL IMPORT Polinom, UbaciMonom, Stampaj, Anuliraj;
- (*izbaci prvih k, izbaci poslednjih k elemenata*);
- PROCEDURE IzbaciPrvihk(VAR p: Polinom; k: INTEGER);
- 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;
- RETURN int;
- END BrEle;
- VAR
- tek : Polinom;
- pro, i : INTEGER;
- ima : BOOLEAN;
- BEGIN
- pro := BrEle(p,ima);
- IF NOT ima THEN
- WriteString('Nema monoma u polinomu!');
- WriteLn;
- WriteString('Polinom je i dalje isti: ');
- Stampaj(p,0);
- WriteLn; WriteLn;
- ELSE
- IF p = NIL THEN
- WriteString('Polinom p je prazan ');
- WriteLn;
- ELSIF k = 0 THEN
- WriteString('Ne izbacuje se ni jedan element, k = 0');
- WriteLn;
- ELSIF k > pro THEN
- WriteString('Ima vise elemenata za izbaciti nego monoma, k > brojmonoma ');
- WriteLn;
- ELSIF k = pro THEN
- p := NIL;
- WriteString('Polinom posle izbacivanja svih: ');
- Stampaj(p,0);
- WriteLn; WriteLn;
- ELSE
- FOR i := 1 TO k DO
- tek := p;
- p := p^.veza;
- DISPOSE(tek)
- END;
- WriteString('Polinom posle izbacivanja ');
- WriteInt(k,0);
- WriteString(' elemenata, izgleda ovako: ');
- Stampaj(p,0);
- WriteLn; WriteLn;
- END
- END
- END IzbaciPrvihk;
- PROCEDURE IzbaciPoslednjihk(VAR p: Polinom; k: INTEGER);
- 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;
- RETURN int;
- END BrEle;
- VAR
- tek, prethodni : Polinom;
- pro, i : INTEGER;
- ima : BOOLEAN;
- BEGIN
- pro := BrEle(p,ima);
- IF NOT ima THEN
- WriteString('Nema monoma u polinomu!');
- WriteLn;
- WriteString('Polinom je i dalje isti: ');
- Stampaj(p,0);
- WriteLn; WriteLn;
- ELSE
- IF p = NIL THEN
- WriteString('Polinom p je prazan ');
- WriteLn;
- ELSIF k = 0 THEN
- WriteString('Ne izbacuje se ni jedan element, k = 0');
- WriteLn;
- ELSIF k > pro THEN
- WriteString('Ima vise elemenata za izbaciti nego monoma, k > brojmonoma ');
- WriteLn;
- ELSIF k = pro THEN
- p := NIL;
- WriteString('Polinom posle izbacivanja svih: ');
- Stampaj(p,0);
- WriteLn; WriteLn;
- ELSE
- FOR i := 1 TO k DO
- tek := p;
- prethodni := NIL;
- WHILE tek^.veza <> NIL DO
- prethodni := tek;
- tek := tek^.veza
- END;
- prethodni^.veza := NIL;
- DISPOSE(tek)
- END;
- WriteString('Polinom posle izbacivanja ');
- WriteInt(k,0);
- WriteString(' elemenata, izgleda ovako: ');
- Stampaj(p,0);
- WriteLn; WriteLn;
- END
- END
- END IzbaciPoslednjihk;
- VAR
- monom, polinom: Polinom;
- k: 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;
- (*Izrealizovati unos i poziv procedure npr.
- WriteString('Unesite k: ');
- ReadInt(k); WriteLn;
- IzbaciPrvihk(polinom,k);
- *)
- END Polinomija.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement