| | |
Recursive procedure (to display a linked list)
Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Jan 2008
Posts: 19
Reputation:
Solved Threads: 0
Hi again, this is a simple programme that I can't make work
in turbo pascal.
Write a program to create a new list and then display it through a Recursive Procedure ( and use 'p' as a local variable).
This is what I could do but considering I hate procedures and functions it gives me the 'OverFlow' error.
I think the procedure of creation is ok but the recursive one must be chaged.
Any help?
in turbo pascal.Write a program to create a new list and then display it through a Recursive Procedure ( and use 'p' as a local variable).
This is what I could do but considering I hate procedures and functions it gives me the 'OverFlow' error.
I think the procedure of creation is ok but the recursive one must be chaged.
Any help?
Program List56; Uses CRT; Type student=^pointer; pointer=record name:string[10]; next:student; end; Var org, p1 :student; Procedure Cr8List; Begin new(p1); org:=nil; p1:=org; Writeln('Type the names of the students,( hit enter to stop).'); Writeln; writeln; Write('Name: '); readln(p1^.name); While p1^.name <> '' do Begin p1^.next:=org; org:=p1; Write('Name: '); new(p1); readln(p1^.name); end; end; Procedure RecursiveDisplay(p:student); begin while p<> nil do begin Writeln('Name: ',p^.name); p:=p^.next; AfishimRekursiv(p); dispose(p); end; end; Begin CLRSCR; Cr8List; p1:=org; RecursiveDisplay(p1); end.
Learning is the process whereby knowledge is created, through the tranformation of experience...
I think that you need to increase your stack size.
You can do it from the Options -> Compiler -> Memory Sizes menu or use the $M directive at the top of your code.
Let me know if this helps.
You can do it from the Options -> Compiler -> Memory Sizes menu or use the $M directive at the top of your code.
Pascal Syntax (Toggle Plain Text)
{$M 32768, 655360} { Twice the default stack size, default heap size } program fooey; begin writeln( 'Hello world!' ) end.
Let me know if this helps.
•
•
Join Date: Jun 2007
Posts: 36
Reputation:
Solved Threads: 6
Helo Olsi009
i think that some of your programs statements is in a wrong Order I try to correct them and write the new programe as below
Program List56;
Uses CRT;
Type
student=^pointer;
pointer=record
name:string[10];
next:student;
end;
Var Head,org, p1 :student;
Name
tring;
Procedure Cr8List;
Begin
//creating the first node of link list
new(p1);
readln(p1^.name);
P1.Next:=Nil; //The Next pointer of last node mast be nil
Head:=P1;// Head points to the first node of link list
Org:=P1; // Org is a temporary Pointer
Writeln('Type the names of the students,( hit enter to stop).');
Writeln;
writeln;
Write('Name: ');
// Creating The rest of the link list
While p1^.name <> '' do
Begin
new(p1);//Create New node
P1.Next:=Nil;// because it is the last created node, it's next pointer mast be nil
Org.Next:=P1;// make a link between previous node and new node
Org:=P1 // Move temporary pointer to last node
Write('Name: ');
readln(p1^.name);
End;
end;
Procedure RecursiveDisplay(p:student);
begin
If P<>Nil Then
Begin
Writeln('Name: ',p^.name);
RecursiveDisplay(p.next);
End
End;
end;
Begin
CLRSCR;
Cr8List;
RecursiveDisplay(Head);
end.
I havent run this programe But I think it mast be work correctly
i think that some of your programs statements is in a wrong Order I try to correct them and write the new programe as below
Program List56;
Uses CRT;
Type
student=^pointer;
pointer=record
name:string[10];
next:student;
end;
Var Head,org, p1 :student;
Name
tring;Procedure Cr8List;
Begin
//creating the first node of link list
new(p1);
readln(p1^.name);
P1.Next:=Nil; //The Next pointer of last node mast be nil
Head:=P1;// Head points to the first node of link list
Org:=P1; // Org is a temporary Pointer
Writeln('Type the names of the students,( hit enter to stop).');
Writeln;
writeln;
Write('Name: ');
// Creating The rest of the link list
While p1^.name <> '' do
Begin
new(p1);//Create New node
P1.Next:=Nil;// because it is the last created node, it's next pointer mast be nil
Org.Next:=P1;// make a link between previous node and new node
Org:=P1 // Move temporary pointer to last node
Write('Name: ');
readln(p1^.name);
End;
end;
Procedure RecursiveDisplay(p:student);
begin
If P<>Nil Then
Begin
Writeln('Name: ',p^.name);
RecursiveDisplay(p.next);
End
End;
end;
Begin
CLRSCR;
Cr8List;
RecursiveDisplay(Head);
end.
I havent run this programe But I think it mast be work correctly
•
•
Join Date: Jan 2008
Posts: 19
Reputation:
Solved Threads: 0
Hi fayyaz,
The program works very well and the list is displayed in the exact order (same with the creation). I just added some '^' to the pointers but it works perfectly. thank you
Also Douas thank you cuz my memory size was 16384 - pitty
The program works very well and the list is displayed in the exact order (same with the creation). I just added some '^' to the pointers but it works perfectly. thank you
Also Douas thank you cuz my memory size was 16384 - pitty
Learning is the process whereby knowledge is created, through the tranformation of experience...
•
•
Join Date: Jan 2008
Posts: 7
Reputation:
Solved Threads: 0
Helo...!
hi fayyaz,
actually, i have to explain it in the seminar, that we hav 2 give in the college, i hav to give the presentation for 10 minutes on it, i m giving the presentation for first time...
so plz tell me the pts that shud i mentioned for the explanation...(i need to explain it with the initial leve, as we are just started learning)
and i need a full program coding to explain...'recursion with link list'.... i m getting it throughly, i m not so good in cocecp of recursion...
so if can u plz provide me a program
....thanks for the help...
hi fayyaz,
actually, i have to explain it in the seminar, that we hav 2 give in the college, i hav to give the presentation for 10 minutes on it, i m giving the presentation for first time...
so plz tell me the pts that shud i mentioned for the explanation...(i need to explain it with the initial leve, as we are just started learning)
and i need a full program coding to explain...'recursion with link list'.... i m getting it throughly, i m not so good in cocecp of recursion...
so if can u plz provide me a program
....thanks for the help...
•
•
Join Date: Jan 2008
Posts: 7
Reputation:
Solved Threads: 0
Helo...!
hi fayyaz,
actually, i have to explain it in the seminar, that we hav 2 give in the college, i hav to give the presentation for 10 minutes on it, i m giving the presentation for first time...
so plz tell me the pts that shud i mentioned for the explanation...(i need to explain it with the initial leve, as we are just started learning)
and i need a full program coding to explain...'recursion with link list'.... i m getting it throughly, i m not so good in cocecp of recursion...
so if can u plz provide me a program
....thanks for the help...
hi fayyaz,
actually, i have to explain it in the seminar, that we hav 2 give in the college, i hav to give the presentation for 10 minutes on it, i m giving the presentation for first time...
so plz tell me the pts that shud i mentioned for the explanation...(i need to explain it with the initial leve, as we are just started learning)
and i need a full program coding to explain...'recursion with link list'.... i m getting it throughly, i m not so good in cocecp of recursion...
so if can u plz provide me a program
....thanks for the help...
![]() |
Other Threads in the Pascal and Delphi Forum
- Previous Thread: Some Pascal Help - Mostly DONE | Just A Little :D
- Next Thread: Importing COM objects
Views: 5037 | Replies: 15
| Thread Tools | Search this Thread |
Tag cloud for Pascal and Delphi






