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: Olsi009 is an unknown quantity at this point 
Solved Threads: 0
Olsi009 Olsi009 is offline Offline
Newbie Poster

Recursive procedure (to display a linked list)

 
0
  #1
Jan 23rd, 2008
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?

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...
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Recursive procedure (to display a linked list)

 
0
  #2
Jan 23rd, 2008
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.

  1. {$M 32768, 655360} { Twice the default stack size, default heap size }
  2. program fooey;
  3. begin
  4. writeln( 'Hello world!' )
  5. end.

Let me know if this helps.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 36
Reputation: fayyaz is an unknown quantity at this point 
Solved Threads: 6
fayyaz fayyaz is offline Offline
Light Poster

Re: Recursive procedure (to display a linked list)

 
0
  #3
Jan 24th, 2008
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;
Nametring;

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
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 19
Reputation: Olsi009 is an unknown quantity at this point 
Solved Threads: 0
Olsi009 Olsi009 is offline Offline
Newbie Poster

Re: Recursive procedure (to display a linked list)

 
0
  #4
Jan 24th, 2008
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
Learning is the process whereby knowledge is created, through the tranformation of experience...
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 7
Reputation: brijkiran is an unknown quantity at this point 
Solved Threads: 0
brijkiran brijkiran is offline Offline
Newbie Poster

Help Me Guys>>>>>

 
0
  #5
Jan 24th, 2008
hi,
plz help me guys , i hav to give an seminar on "the recursive procedure with link list" (pascal) in college......i need some explanation how it works....
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 6
Reputation: jeme is an unknown quantity at this point 
Solved Threads: 0
jeme jeme is offline Offline
Newbie Poster

Re: Recursive procedure (to display a linked list)

 
0
  #6
Jan 24th, 2008
hi i wnat program is calculate adding two number by bostfix
thank you very much......
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 36
Reputation: fayyaz is an unknown quantity at this point 
Solved Threads: 6
fayyaz fayyaz is offline Offline
Light Poster

Re: Recursive procedure (to display a linked list)

 
0
  #7
Jan 24th, 2008
Hi Brijkiran

If you explain that what you want exactly to know I can help you.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 36
Reputation: fayyaz is an unknown quantity at this point 
Solved Threads: 6
fayyaz fayyaz is offline Offline
Light Poster

Re: Recursive procedure (to display a linked list)

 
0
  #8
Jan 24th, 2008
Hi jeme
please Exactly declare What is input and output of your program. it is beter that you give an example about that
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 7
Reputation: brijkiran is an unknown quantity at this point 
Solved Threads: 0
brijkiran brijkiran is offline Offline
Newbie Poster

Re: Recursive procedure (to display a linked list)

 
0
  #9
Feb 8th, 2008
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...
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 7
Reputation: brijkiran is an unknown quantity at this point 
Solved Threads: 0
brijkiran brijkiran is offline Offline
Newbie Poster

Re: Recursive procedure (to display a linked list)

 
0
  #10
Feb 8th, 2008
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...
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Pascal and Delphi Forum


Views: 5037 | Replies: 15
Thread Tools Search this Thread



Tag cloud for Pascal and Delphi
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC