Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MODULE lista_z1;
- // 21.3.2014(3 cas) PMF
- FROM InOut IMPORT ReadInt, WriteInt, WriteLn, WriteString;
- FROM Storage IMPORT ALLOCATE, DEALLOCATE;
- TYPE
- pok = POINTER TO Slog;
- Slog = RECORD
- kinf : INTEGER;
- veza : pok
- END;
- VAR
- lista : pok;
- n, i, broj, bp, b : INTEGER;
- prazna, parni : BOOLEAN;
- PROCEDURE ucitajulistu(VAR lista: pok; broj: INTEGER);
- VAR
- temp : pok;
- BEGIN
- NEW(temp);
- temp^.kinf := broj;
- temp^.veza := lista;
- lista := temp
- END ucitajulistu;
- PROCEDURE stampajlistu(lista: pok);
- VAR
- temp : pok;
- BEGIN
- temp := lista;
- WHILE temp <> NIL DO
- WriteInt(temp^.kinf,0);
- WriteLn;
- temp := temp^.veza
- END;
- END stampajlistu;
- PROCEDURE egzb(lista: pok; b: INTEGER; VAR prazna: BOOLEAN): INTEGER;
- VAR
- ct: INTEGER;
- temp : pok;
- BEGIN
- prazna := FALSE;
- IF lista = NIL THEN
- prazna := TRUE
- END;
- temp := lista;
- ct := 0;
- WHILE temp <> NIL DO
- IF temp^.kinf = b THEN
- ct := ct +1
- END;
- temp := temp^.veza
- END;
- RETURN ct;
- END egzb;
- PROCEDURE egzp(lista: pok): BOOLEAN;
- VAR
- temp : pok;
- BEGIN
- temp := lista;
- WHILE temp <> NIL DO
- IF NOT ODD(temp^.kinf) THEN
- RETURN TRUE
- END
- END;
- RETURN FALSE;
- END egzp;
- PROCEDURE parnie(lista: pok);
- VAR
- temp : pok;
- BEGIN
- temp := lista;
- WHILE temp <> NIL DO
- IF NOT ODD(temp^.kinf) THEN
- WriteInt(temp^.kinf,0);
- WriteLn
- END;
- temp := temp^.veza;
- END
- END parnie;
- PROCEDURE poslednji(lista: pok);
- VAR
- temp : pok;
- BEGIN
- temp := lista;
- IF lista <> NIL THEN
- WHILE temp^.veza <> NIL DO
- temp := temp^.veza
- END;
- WriteInt(temp^.kinf,0)
- END;
- END poslednji;
- PROCEDURE unisti(VAR lista: pok);
- VAR
- temp : pok;
- BEGIN
- temp := lista;
- WHILE temp <> NIL DO
- lista := lista^.veza;
- DISPOSE(temp);
- temp := lista
- END
- END unisti;
- BEGIN
- (*Unos*)
- lista := NIL;
- WriteString('Unesite n elmenata za listu: ');
- ReadInt(n); WriteLn;
- WriteString('Unos elemenata: '); WriteLn;
- FOR i := 1 TO n DO
- ReadInt(broj);
- ucitajulistu(lista,broj)
- END;
- (*Stampa*)
- WriteLn; WriteLn;
- WriteString('Ispis elemenata iz liste: '); WriteLn;
- stampajlistu(lista);
- (*svijednakisa b*)
- WriteLn; WriteLn;
- WriteString('Unesite b: ');
- ReadInt(b);
- WriteLn;
- bp := egzb(lista,b,prazna);
- IF prazna THEN
- WriteString('U listi nema elemenata!');
- WriteLn
- ELSE
- IF bp = 0 THEN
- WriteString('Uneseni broj nije pronadjen u listi!');
- WriteLn
- ELSE
- WriteInt(b,0);
- WriteString(' je pronadjeno u listi ');
- WriteInt(bp,0);
- WriteString('. puta.'); WriteLn
- END
- END;
- (*stamapj parne*)
- WriteLn; WriteLn;
- parni := egzp(lista);
- IF parni THEN
- WriteString('Parni elementi su: ');
- parnie(lista); WriteLn
- ELSE
- WriteString('Nema parnih elemenata.');
- WriteLn
- END;
- (*Stampaj poslednji*)
- WriteLn;
- IF prazna THEN
- WriteString('U listi nema elemenata!')
- ELSE
- WriteString('Poslednji element u listi je: ');
- poslednji(lista)
- END;
- (*Unisti listu*)
- unisti(lista);
- WriteLn;
- WriteString('Kraj programa.')
- END lista_z1.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement