Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27902
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Implement linked list in JavaScript? |
| Date | 2015-05-26 21:33 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <mk2orv$iqq$3@dont-email.me> (permalink) |
| References | <k6-dnS5P1bUo1PnInZ2dnUVZ5vednZ2d@giganews.com> |
On Tue, 26 May 2015 03:23:48 -0700, Robert Crandal wrote:
> I am somewhat new to JavaScript, so I'm not entirely sure how to go
> about this. Can my double linked list structure be simulated as an
> array of objects? Or is there a different way to implement this?
What operations do you carry out on a doubly linked list:
1) prepend an element at the start of a list
2) append an element to the end of a list
3) insert one element or a sequence of elements at an arbitrary point in
a list
4) remove an element or sequence of elements from an arbitrary point in a
list
5) walk a list forwards
6) walk a list backwards
7) remove the last element from a list
8) remove the first element from a list
9) delete an element from a list
10) change the value of an element in a list
I think all of these can be done in javascript using an array.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/
Global_Objects/Array
Look at the shift, unshift, pop, push, slice and splice array methods.
walking forwards through an array is easy:
for (i = 0; i < array.length; i++) {
// do something with the ith element
}
and walking backwards:
i = array.length;
while (i--) {
// do something with the ith element
}
--
Denis McMahon, denismfmcmahon@gmail.com
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Implement linked list in JavaScript? "Robert Crandal" <noreplytome@yahoo.com> - 2015-05-26 03:23 -0700
Re: Implement linked list in JavaScript? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-26 13:25 +0200
Re: Implement linked list in JavaScript? Steven D'Aprano <steve@pearwood.info> - 2015-05-26 22:35 +1000
Re: Implement linked list in JavaScript? Scott Sauyet <scott.sauyet@gmail.com> - 2015-05-26 07:17 -0700
Re: Implement linked list in JavaScript? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2015-05-30 06:11 -0700
Re: Implement linked list in JavaScript? Scott Sauyet <scott.sauyet@gmail.com> - 2015-06-04 19:22 -0700
Re: Implement linked list in JavaScript? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2015-06-10 18:42 -0700
Re: Implement linked list in JavaScript? Scott Sauyet <scott.sauyet@gmail.com> - 2015-06-11 05:57 -0700
Re: Implement linked list in JavaScript? Denis McMahon <denismfmcmahon@gmail.com> - 2015-05-26 21:33 +0000
Re: Implement linked list in JavaScript? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2015-05-27 20:01 -0700
csiph-web