Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Something Not Understood ABout LinkedList Posted by sad.boy on 7 Aug 2006 at 2:58 AM
first check this code out ;)

 type
       mypointer = ^queue;
        queue = record
        data: integer;
        next: mypointer;
  end;

 var
   first, last, current: mypointer;


procedure add(i: integer);
begin
   new(current); 
   current^.data := i; 
   currebt^.next := nil;
   if first = nil then 
      first := current 
   else
       last^.next := current;        >>Check Me
       last := current; 
end;

procedure view;

 begin
   current := first;
   while current <> nil do
      begin
         writeln(current^.data); 
         current := curent^.next;   >>check Me
      end;
end;
  


i have problem getting those lines marked by "Check Me"
how the next item is accessed? i can't get the logic of those lines
i followed them a couple of times but how next filed points to the
next i item in the queue?

any Help IS Greatly appricitated ;)
Report
Re: Something Not Understood ABout LinkedList Posted by zibadian on 7 Aug 2006 at 3:04 AM
: first check this code out ;)
:
:
:  type
:        mypointer = ^queue;
:         queue = record
:         data: integer;
:         next: mypointer;
:   end;
: 
:  var
:    first, last, current: mypointer;
: 
: 
: procedure add(i: integer);
: begin
:    new(current); 
:    current^.data := i; 
:    currebt^.next := nil;
:    if first = nil then 
:       first := current 
:    else
:        last^.next := current;        >>Check Me
:        last := current; 
: end;
: 
: procedure view;
: 
:  begin
:    current := first;
:    while current <> nil do
:       begin
:          writeln(current^.data); 
:          current := curent^.next;   >>check Me
:       end;
: end;
:   

:
: i have problem getting those lines marked by "Check Me"
: how the next item is accessed? i can't get the logic of those lines
: i followed them a couple of times but how next filed points to the
: next i item in the queue?
:
: any Help IS Greatly appricitated ;)
:
The Next field is a pointer, which points to the memory location of the next record. The ^ after a pointer dereferences it, allowing you to gain access to its actual data. As long as you don't dereference a pointer, it is simply a memory location, which can point to anywhere within the memory without knowing what is stored at that location.
Report
Re: Something Not Understood ABout LinkedList Posted by sad.boy on 15 Aug 2006 at 1:28 AM
: : first check this code out ;)
: :
: :
: :  type
: :        mypointer = ^queue;
: :         queue = record
: :         data: integer;
: :         next: mypointer;
: :   end;
: : 
: :  var
: :    first, last, current: mypointer;
: : 
: : 
: : procedure add(i: integer);
: : begin
: :    new(current); 
: :    current^.data := i; 
: :    currebt^.next := nil;
: :    if first = nil then 
: :       first := current 
: :    else
: :        last^.next := current;        >>Check Me
: :        last := current; 
: : end;
: : 
: : procedure view;
: : 
: :  begin
: :    current := first;
: :    while current <> nil do
: :       begin
: :          writeln(current^.data); 
: :          current := curent^.next;   >>check Me
: :       end;
: : end;
: :   

: :
: : i have problem getting those lines marked by "Check Me"
: : how the next item is accessed? i can't get the logic of those lines
: : i followed them a couple of times but how next filed points to the
: : next i item in the queue?
: :
: : any Help IS Greatly appricitated ;)
: :
: The Next field is a pointer, which points to the memory location of the next record. The ^ after a pointer dereferences it, allowing you to gain access to its actual data. As long as you don't dereference a pointer, it is simply a memory location, which can point to anywhere within the memory without knowing what is stored at that location.
:

in the line below what filed of current record is stored in last^.next?

last^.next := current; >>Check Me

Report
Re: Something Not Understood ABout LinkedList Posted by zibadian on 15 Aug 2006 at 7:44 AM
: : : first check this code out ;)
: : :
: : :
: : :  type
: : :        mypointer = ^queue;
: : :         queue = record
: : :         data: integer;
: : :         next: mypointer;
: : :   end;
: : : 
: : :  var
: : :    first, last, current: mypointer;
: : : 
: : : 
: : : procedure add(i: integer);
: : : begin
: : :    new(current); 
: : :    current^.data := i; 
: : :    currebt^.next := nil;
: : :    if first = nil then 
: : :       first := current 
: : :    else
: : :        last^.next := current;        >>Check Me
: : :        last := current; 
: : : end;
: : : 
: : : procedure view;
: : : 
: : :  begin
: : :    current := first;
: : :    while current <> nil do
: : :       begin
: : :          writeln(current^.data); 
: : :          current := curent^.next;   >>check Me
: : :       end;
: : : end;
: : :   

: : :
: : : i have problem getting those lines marked by "Check Me"
: : : how the next item is accessed? i can't get the logic of those lines
: : : i followed them a couple of times but how next filed points to the
: : : next i item in the queue?
: : :
: : : any Help IS Greatly appricitated ;)
: : :
: : The Next field is a pointer, which points to the memory location of the next record. The ^ after a pointer dereferences it, allowing you to gain access to its actual data. As long as you don't dereference a pointer, it is simply a memory location, which can point to anywhere within the memory without knowing what is stored at that location.
: :
:
: in the line below what filed of current record is stored in last^.next?
:
: last^.next := current; >>Check Me
:
:
The memory address of Current is stored.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.