why Access Violation Послано Dilyan 8 май 2005 22:06 type el = ^t; t = record link : el; val : longint; end; var a : array[0..2000] of pointer; i, j, k, l, o, m, n, pp1, pp2 : longint; p, q : el; s, s1, st, msg, p1, p2 : string; int : integer; f : text; begin assign(f, ''); reset(f); readln(f, n); for i := 1 to n do begin readln(f, s); msg := ''; p1 := ''; p2 := ''; while s[1] <> ' ' do begin msg := msg + s[1]; delete(s, 1, 1); end; while s[1] = ' ' do delete(s, 1, 1); while (s[1] >= '0') and (s[1] <= '9') and (s <> '') do begin p1 := p1 + s[1]; delete(s, 1, 1); end; if msg = 'PUSH' then begin while s[1] = ' ' do delete(s, 1, 1); while (s[1] >= '0') and (s[1] <= '9') and (s <> '') do begin p2 := p2 + s[1]; delete(s, 1, 1); end; end; val(p1, pp1, int); if msg = 'PUSH' then val(p2, pp2, int); if msg = 'POP' then begin p := a[pp1]; writeln(p^.val); a[pp1] := p^.link; end else begin new(p); p^.val := pp2; p^.link := a[pp1]; a[pp1] := p; end; end; close(f); end. Re: USE CHAR I ALSO HAD THIS PROBLEM, YOU SHOULD USE CHAR NOT STRING type el = ^t; t = record link : el; val : longint; end; var a : array[0..2000] of pointer; i, j, k, l, o, m, n, pp1, pp2 : longint; p, q : el; s, s1, st, msg, p1, p2 : string; int : integer; f : text; begin assign(f, ''); reset(f); readln(f, n); for i := 1 to n do begin readln(f, s); msg := ''; p1 := ''; p2 := ''; while s[1] <> ' ' do begin msg := msg + s[1]; delete(s, 1, 1); end; while s[1] = ' ' do delete(s, 1, 1); while (s[1] >= '0') and (s[1] <= '9') and (s <> '') do begin p1 := p1 + s[1]; delete(s, 1, 1); end; if msg = 'PUSH' then begin while s[1] = ' ' do delete(s, 1, 1); while (s[1] >= '0') and (s[1] <= '9') and (s <> '') do begin p2 := p2 + s[1]; delete(s, 1, 1); end; end; val(p1, pp1, int); if msg = 'PUSH' then val(p2, pp2, int); if msg = 'POP' then begin p := a[pp1]; writeln(p^.val); a[pp1] := p^.link; end else begin new(p); p^.val := pp2; p^.link := a[pp1]; a[pp1] := p; end; end; close(f); end. |