Hello,
Say I want to implement a kind of linked list which node data may be anything.
Thus I cannot store data on place (in nodes), indeed; so it should be
referenced. But pointers themselves are supposed to be typed. So, how can I do
that?
type list = ^node;
node = record
data : ???;
next : list;
end;
I tried to use Pointer, but then I get an error saying the compiler found <some
type> while it expected "untyped". What is the use of Pointer (without type for
pointed data)?
I also had a look at Variant; this looks like an ugly hack ;-) And avyway is
not really generic. I need data to ba able to be anything, including first a
linked list itself...
Finaly, when trying to write the the algo for a given type, I get an issue
since the def above is recursive, recursively pointing in fact. So, I need to
stop the run somewhere by allocating the memory for non-yet-existing data
pointed by a pointer -- I guess.
p^ := <I'll tell you soon, just book the place>
(The compiler warns about not initialised pointers.)
Pointers (sic!) to implementations of similar things (including trees)
welcome...
More generally, I cannot find in the library units for common data structures
(sequence, associative table, set (the collection)...).
Denis
________________________________
vit esse estrany ☣
spir.wikidot.com
_______________________________________________
fpc-pascal maillist - [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal