: : : 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.