Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MODULE liste;
- FROM InOut IMPORT WriteString, WriteLn, ReadInt, WriteInt;
- FROM Storage IMPORT ALLOCATE, DEALLOCATE;
- TYPE
- pok = POINTER TO Slog;
- Slog = RECORD
- kinf : INTEGER;
- veza : pok
- END;
- ProcTip = PROCEDURE (VAR pok,INTEGER);
- VAR
- lista: pok;
- odabir : INTEGER;
- PROCEDURE stampaj(VAR lista: pok); FORWARD;
- PROCEDURE unisti(VAR lista: pok); FORWARD;
- PROCEDURE obrni(VAR lista:pok); FORWARD;
- PROCEDURE dodajpocetak(VAR lista: pok;int : INTEGER);
- VAR
- temp : pok;
- BEGIN
- NEW(temp);
- temp^.kinf := int;
- temp^.veza := lista;
- lista := temp
- END dodajpocetak;
- PROCEDURE dodajkraj(VAR lista: pok;int: INTEGER);
- VAR
- temp, tekuci : pok;
- BEGIN
- NEW(temp);
- temp^.kinf := int;
- temp^.veza := NIL;
- IF lista = NIL THEN
- lista := temp
- ELSE
- tekuci := lista;
- WHILE tekuci^.veza <> NIL DO
- tekuci := tekuci^.veza
- END;
- tekuci^.veza := temp
- END
- END dodajkraj;
- PROCEDURE ucitaj(VAR lista: pok;p: ProcTip);
- VAR
- i, n , int : INTEGER;
- BEGIN
- WriteString('Unesite n: ');
- ReadInt(n);
- FOR i := 1 TO n DO
- ReadInt(int);
- p(lista,int);
- WriteLn
- END;
- WriteLn;
- WriteString('Stampanje liste: ');
- WriteLn;
- stampaj(lista);
- WriteLn;
- END ucitaj;
- PROCEDURE stampaj(VAR lista: pok);
- VAR
- temp : pok;
- BEGIN
- temp := lista;
- WHILE temp <> NIL DO
- WriteInt(temp^.kinf,0);
- WriteLn;
- temp := temp^.veza
- END;
- END stampaj;
- PROCEDURE unisti(VAR lista: pok);
- VAR
- temp : pok;
- BEGIN
- temp := lista;
- WHILE lista <> NIL DO
- DISPOSE(temp);
- lista := lista^.veza;
- temp := lista
- END
- END unisti;
- PROCEDURE demonstrirajobrni(VAR lista: pok);
- BEGIN
- WriteString('Pre obrtanja!');
- WriteLn;
- stampaj(lista);
- WriteLn;
- WriteString('Posle obrtanja! ');
- WriteLn;
- obrni(lista);
- stampaj(lista);
- END demonstrirajobrni;
- PROCEDURE obrni(VAR lista:pok);
- VAR
- temp,nova,pred:pok;
- BEGIN
- nova := NIL;
- temp := lista;
- pred := NIL;
- WHILE temp # NIL DO
- dodajpocetak(nova,temp^.kinf);
- pred := temp;
- temp := temp^.veza;
- DISPOSE(pred);
- END;
- lista := nova;
- END obrni;
- BEGIN
- lista := NIL;
- WriteString('Dodaj pocetak ili dodaj kraj, 1/2: ');
- ReadInt(odabir); WriteLn;
- IF odabir = 1 THEN
- ucitaj(lista,dodajpocetak);
- ELSIF odabir = 2 THEN
- ucitaj(lista,dodajkraj);
- ELSE
- WriteString('Pogresan unos! ')
- END;
- demonstrirajobrni(lista);
- unisti(lista);
- END liste.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement