in reply to Re^4: Perl linked list
in thread Perl linked list
If you look at the code I posted, it is really not very complicated.
I am starting with the terminator, the last element of the linked list. Therefore, the next field is undefined and the value is "D". The $pt variable (for "pointer", but I should not use that terminology, it is a reference, not a pointer) is something that gives me access to the data structure. This reference will be used in the next code line:my $pt = { value => "D", next => undef };
There, I am saying that the value is "C", and that the next record is the one I just created before. And so on until the first element. Please feel free to ask if you don't understand.my $pt2 = {value => "C", next => $pt};
In lower level languages such as C or C++, linked lists are needed much more often and they are also often more difficult to implement.
|
|---|