ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1136. Parliament

crash acess violation #1
Posted by jet-pilot 22 Oct 2012 21:16
WHY?


type hlist=^list;

list=record
    data: longint;
    l,r: hlist;
    end;


var n,i:longint;
    a:array[1..3000] of longint;
    head: hlist;

procedure add(var v:hlist; x:longint);
    begin
    if v=nil then
        begin
        new(v);
        v^.data:=x;
        end
    else if x>v^.data then add(v^.r, x)
                     else add(v^.l, x);
    end;

procedure draw(var v:hlist);
        begin
        if not (v=nil) then
            begin
            draw(v^.r);
            draw(v^.l);
            write(v^.data,' ');
            dispose(v);
            end;
        end;
begin
readln(n);
for i:=n downto 1 do read(a[i]);
for i:=1 to n do add(head, a[i]);
draw(head);
end.
Re: crash acess violation #1
Posted by Rusu_Alexei 2 Nov 2012 00:22
The same error!
I don't understand why and what does mean acess violation?
Help, please!

program p1136;
  type arbore=^nod;
       nod=record
             info:word;
             left,right:arbore;
           end;
  var t,r,q:arbore;
      n,i:integer;
      a:array [1..3000] of word;
procedure postordine(t:arbore);
  begin
    if t<>nil then
      begin
        postordine(t^.right);
        postordine(t^.left);
        write(t^.info,' ');
      end;
  end;
begin
  readln(n);
  for i:=n downto 1 do read(a[i]);
  new(t);new(q);new(r);t^.info:=a[1];
  for i:=2 to n do
    begin
      r:=t;
      while q<>nil do
        begin
          if a[i]>r^.info then begin new(q);q:=r^.right;end
                          else begin new(q);q:=r^.left;end;
          if q<>nil then r:=q;
        end;
      new(q);q^.info:=a[i];
      if r^.info<a[i] then r^.right:=q else r^.left:=q;
    end;
  postordine(t);
end.