Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MODULE lista_z2;
- FROM FIO IMPORT Open, Create, WrStr, RdStr, EOF, File, WrLn, Close;
- FROM InOut IMPORT WriteString, WriteLn, ReadString, Read;
- FROM Storage IMPORT ALLOCATE, DEALLOCATE;
- FROM Str IMPORT Compare;
- TYPE
- STRING = ARRAY [1..20] OF CHAR;
- pok = POINTER TO Slog;
- Slog = RECORD
- kinf : STRING;
- veza : pok
- END;
- VAR
- str, tacka, strp : STRING;
- lista : pok;
- f: File;
- odabir : CHAR;
- again, pro, pripada : BOOLEAN;
- PROCEDURE stampajlistu(lista: pok);
- VAR
- temp : pok;
- BEGIN
- temp := lista;
- WHILE temp <> NIL DO
- WriteString(temp^.kinf);
- WriteLn;
- temp := temp^.veza
- END;
- END stampajlistu;
- PROCEDURE ucitajulistu(VAR lista: pok; str: STRING);
- VAR
- temp : pok;
- BEGIN
- NEW(temp);
- temp^.kinf := str;
- temp^.veza := lista;
- lista := temp
- END ucitajulistu;
- 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;
- PROCEDURE proverapripadnosti(lista : pok; sp: STRING): BOOLEAN;
- VAR
- temp : pok;
- BEGIN
- temp := lista;
- WHILE temp <> NIL DO
- IF Compare(temp^.kinf,sp) = 0 THEN
- RETURN FALSE
- END;
- temp := temp^.veza;
- END;
- RETURN TRUE;
- END proverapripadnosti;
- PROCEDURE dodajulistu(lista: pok; sp: STRING);
- VAR
- temp, tekuci : pok;
- BEGIN
- NEW(temp);
- temp^.kinf := sp;
- 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 dodajulistu;
- BEGIN
- WriteString('Da li postoji fajl iz kojeg zelite da ucitate imena? (d/n) ');
- again := FALSE;
- REPEAT
- Read(odabir);
- IF again THEN
- WriteString('Unesite opet, unos mora biti (d/n) : ');
- WriteLn;
- END;
- WriteLn;
- again := TRUE;
- UNTIL (CAP(odabir) = 'D') OR (CAP(odabir) = 'N');
- IF CAP(odabir) = 'D' THEN
- lista := NIL;
- f := Open('imena.txt'); (*ovde unos imena fajla iz kojeg zelite ucitavanje*)
- WHILE NOT EOF DO
- RdStr(f,str);
- ucitajulistu(lista,str)
- END;
- ELSIF (CAP(odabir) = 'N') THEN
- lista := NIL;
- tacka := '.';
- f := Create('nekoime20.txt'); (*ime fajla koji ce se kreirati*)
- WriteString('Unosite imena, sa "." se unos zavrsava');
- WriteLn;
- ReadString(str);
- WriteLn;
- IF Compare(str,tacka) = 0 THEN
- pro := TRUE;
- END;
- WHILE NOT pro DO
- WrStr(f,str);
- WrLn(f);
- ReadString(str);
- IF Compare(str,tacka) = 0 THEN
- pro := TRUE;
- END
- END;
- WHILE NOT EOF DO
- RdStr(f,str);
- ucitajulistu(lista,str)
- END;
- END;
- stampajlistu(lista);
- WriteLn; WriteLn;
- WriteString('Unesite ime za koje zelite da proverite da li se'); WriteLn;
- WriteString('nalazi u listi: ');
- ReadString(strp);
- WriteLn;
- pripada := proverapripadnosti(lista,strp);
- pripada := FALSE;
- IF pripada THEN
- WriteString('Nalazi se u listi!');
- Close(f);
- unisti(lista)
- ELSE
- WriteString('Ne nalazi se!'); WriteLn;
- WriteString('Dodavanje imena u listu');
- dodajulistu(lista,strp);
- WriteString('Lista sa dodatim strinogm izgleda ovako: ');
- WriteLn;
- stampajlistu(lista);
- unisti(lista)
- END;
- END lista_z2.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement