Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project1;
- uses
- crt, DOS;
- type
- listPtr = ^list;
- list = record
- next: listPtr;
- previous: listPtr;
- x: String;
- end;
- procedure push(var listStart: listPtr; var listEnd: listPtr; y: String);
- var
- newElement: listPtr;
- begin
- clrScr;
- if listEnd = NIL then
- begin
- newElement := listStart;
- new(newElement);
- newElement^.x := y;
- newElement^.next := NIL;
- newElement^.previous := NIL;
- listEnd := newElement;
- listStart := newElement;
- end else
- begin
- newElement := listEnd;
- New(newElement^.next);
- newElement := newElement^.next;
- newElement^.x := y;
- newElement^.next := NIL;
- newElement^.previous := listEnd;
- listEnd := newElement;
- end;
- end;
- function pop(var listStart: listPtr; var listEnd: listPtr): String;
- var
- pointer: listPtr;
- begin
- if listStart^.next = NIL then
- begin
- pointer := listStart;
- pop := pointer^.x;
- dispose(pointer);
- listStart := NIL;
- listEnd := NIL;
- end else
- begin
- pointer := listEnd;
- listEnd := pointer^.previous;
- listEnd^.next := NIL;
- pop := pointer^.x;
- dispose(pointer);
- end;
- end;
- function isEmpty(var listStart: listPtr): Boolean;
- begin
- clrScr;
- if listStart = NIL then
- isEmpty := True
- else
- isEmpty := False;
- end;
- function readBracket(var listStart: listPtr; var listEnd: listPtr): Boolean;
- var
- line: String;
- begin
- readBracket := True;
- writeLn('Wprowadz nawias lub 0, aby zakonczyc: ');
- ReadLn(line);
- if (line = '{') or (line = '(') then
- begin
- push(listStart, listEnd, line);
- end else if (line = ')') then
- begin
- if not isEmpty(listStart) then
- begin
- if pop(listStart, listEnd) = '(' then
- begin
- writeLn('Nawias pasuje!');
- delay(500);
- end else
- begin
- readBracket := False;
- writeLn('Nawias NIE pasuje!');
- delay(500);
- end;
- end else
- begin
- writeLn('Brak nawiasow na stosie!');
- delay(500);
- end;
- end else if (line = '}') then
- begin
- if not isEmpty(listStart) then
- begin
- if pop(listStart, listEnd) = '{' then
- begin
- writeLn('Nawias pasuje!');
- delay(500);
- end else
- begin
- readBracket := False;
- writeLn('Nawias NIE pasuje!');
- delay(500);
- end;
- end else
- begin
- writeLn('Brak nawiasow na stosie!');
- delay(500);
- end;
- end else if (line = '0') then
- begin
- readBracket := False;
- if isEmpty(listStart) then
- begin
- writeLn('Nawiasowanie poprawne!');
- end else
- begin
- writeLn('Nawiasowanie bledne!');
- end;
- delay(500);
- end else
- begin
- writeLn('Bledne dane wejsciowe, wpisz jeszcze raz!');
- delay(500);
- end;
- end;
- var
- listStart, listEnd: listPtr;
- go: Boolean;
- begin
- listEnd:= NIL;
- listStart := NIL;
- go := True;
- clrScr;
- while go do
- begin
- clrScr;
- go := readBracket(listStart, listEnd);
- end;
- writeLn('Nacisnij dowolny klawisz aby wyjsc...');
- ReadKey;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement