Evertjan.
5/26/2015 11:26:00 AM
"Robert Crandal" <noreplytome@yahoo.com> wrote on 26 mei 2015 in
comp.lang.javascript:
> I am interested in implementing a doubly linked list data
> structure with JavaScript, if it's even possible.
There are no lists in js. At least the notion escapes me.
> I typically implement my doubly linked list using C or C++,
> as a linked list of "nodes". Each node contains previous and
> next pointers to nodes that are adjacent.
There is only "runtime" in a scripting language.
Any compiling is done virtually at the same time.
> A node is typically an object or data structure
> that is allocated at run time.
Why typically? Is it or isn't it?
The whole idea of allocation is a precompiling thought.
Runtime allocation and deallocation in JS are done automachically.
Allocation being done on-demand,
and deallocation being called garbage-collection.
> Typical node operations on my linked list include push, pop,
> append, delete, insert (anywhere in list), etc, etc.. I also
> have functions that can walk through my list and search for
> any node, forwards or backwards, left or right, beginning at
> any node index.
Sorry, every language has its nuice and its nasy things.
Better learn about a language, than trying to implement the tricks
"out of context".
However, if you want to make an array of objects,
where only objects exist when and where you need them,
those objects having the methods and properties you want them to give,
and if you understand what you are doing, js is a good choice.
If you want to play with pointers, and not think an array as having a
natural order, well that is your choice of programming.
var a = [];
a[1] = [12345,'x'];
a[12345] = [1,'y'];
No hands, mama,
this 'single linked' array has only 2 members "allocated".
> I am somewhat new to JavaScript, so I'm not entirely sure
> how to go about this. Can my double linked list structure
We don't even know what that is, bus seen the above,
it is a simple as .., if again you know what you are doing.
> be simulated as an array of objects?
Here you go again, If you start thinking you are symulating another
language, you will stay "somewhat new to JavaScript" forever and ever.
> Or is there a different way to implement this?
You should not even want to implement such simulation.
It is like speaking a human language by just translating your thought in
your native one "at runtime".
Better learn and trust yourself thinking in that language.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)