Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Pascal programming error. Could anybody help?
so I've got t a Pascal binary tree DFS search app. It compiles well but when I run it I get exitcode error 216? How can I fix it?
program prg;
uses crt;
type
ptrnode=^node;
node = record
data: char;
l,r: ptrnode;
end;
pnode=^rnode;
rnode=record
open:char;
link:pnode;
end;
procedure add(var p: ptrnode; x :char);
begin
if p <> nil then begin
if x > p^.data then add(p^.r,x);
if x < p^.data then add(p^.l,x);
{if x = p^.data then writeln('This element already exist');}
end
else begin
p:=new(ptrnode);
p^.data:=x;
p^.l:=nil;
p^.r:=nil;
end;
end;
procedure print(p: ptrnode; n: integer);
var i: integer;
begin
if p <> nil then begin
if p^.r <> nil then print(p^.r,n+1);
for i:=1 to n do write(' '); writeln(p^.data);
if p^.l <> nil then print(p^.l,n+1);
end;
end;
procedure del(var p: ptrnode);
begin
if p <> nil then begin
if p^.r <> nil then del(p^.r);
if p^.l <> nil then del(p^.l);
dispose(p);
end;
end;
function depth(p: ptrnode): integer; {вычисляет глубину дерева}
var dr,dl: integer;
begin
if p <> nil then begin
if (p^.r <> nil) then dr:=depth(p^.r)+1;
if (p^.l <> nil) then dl:=depth(p^.l)+1;
end;
if dr > dl then depth:=dr else depth:=dl;
end;
procedure step(p: ptrnode;lavel,stop: integer); {эта поцидура распечатывает все узлы уровня stop}
begin
if p <> nil then begin
if lavel=stop then writeln(p^.data);
if (p^.r <> nil) then step(p^.r,lavel+1,stop);
if (p^.l <> nil) then step(p^.l,lavel+1,stop);
end;
end;
function push(top:pnode; open:char):pnode;
var p:pnode;
begin
new(p);
p^.open:=open;p^.link:=top;
push:=p;
end;
function pop(top:pnode; var open:char):pnode;
var p:pnode;
begin
open:=top^.open;
pop:=top^.link;
dispose(top);
end;
var
root: ptrnode;
i: integer;
close:string;
top:pnode;
x:char;
begin
clrscr;
close:='';
top:=nil;
root:=nil;
add(root,'a');
add(root,'c');
add(root,'d');
add(root,'b');
add(root,'h');
add(root,'e');
add(root,'o');
print(root,0);
for i:=1 to depth(root) do step(root,1,i);
top:=push(top,root^.data);
{ write(top^.open)};
while x<>'o' do begin
while root<>nil do begin
top:=pop(top,x); close:=close+x;
if root^.l<>nil then begin
top:=push(top,root^.l^.data);
root:=root^.l; end
else begin
if root^.r<>nil then begin
top:=push(top,root^.r^.data);
root:=root^.r; end
else del(root);
end; end; end;
{ write;}
readln;
{ del(root); }
readkey;
end.
3 Answers
- mystic smegLv 61 decade agoFavorite Answer
Hey Sende,
:D
If you read my last post to your previous question, I gave you my mail address so you could ask me questions (just like this one). I also asked you to send me a mail address so I could send you the source code I've written for you. I'm not mad at you though; actually the opposite because you've done your own solution (which is pretty good). But It might have been nice of you to tell me I was wasting my time. ;)
That said, I'll take a look at the code you have posted and let you know what I find. In all honesty, I think your code is simpler than mine (although mine works ;). Although I've done 'node objects' in Pascal and it's probably too complex. It’s nice to see that we used pretty much the same approach though. :)
Is this the tree you wanted in memory? - does it look right for a search?
L-[a]-R
|
L-[c]-R
| |
[b] [d]-R
|
L-[h]-R
| |
[e] [o]
-----------------------
I went through your code last night, and aside from the tree you build in memory, which may be incorrect for your requirements, you are trying to dispose of a nil pointer. It happens after a call to “else del(root);“ in the pop() procedure.
Unfortunately, you haven’t commented your code. So I’m unable to ascertain what you’re aiming for in your program. You should try tracing your code using F7. This will help you see where the error is, and it should be pretty easy to fix (e.g. don’t dispose of a nil pointer).
Again, feel free to mail me at mystic.smeg@yahoo.co.uk, maybe I can send you my source to look at. :)
na
- ?Lv 44 years ago
form of, a minimum of from the playing element. playing probable has countless roots, i.e. attempting to kill a prey whilst they're interior of questionable distance, attempting a sparkling nutrition, working whilst there may be threat. in spite of the undeniable fact that, concept and needing others to have self belief probable has a foundation besides as this would have helped capability a small social team. Then too, our means to manage symbols additionally contributes to the blend.