From: Austin Ziegler Date: 2005-04-05T04:16:50+09:00 Subject: Re: doubly linked list in Ruby? On Apr 4, 2005 2:39 PM, ed_davis2 wrote: > I've gone through a Ruby tutorial, and have been writing some > simple programs. > > But I have a question: how would I implement a simple doubly > linked list of strings in Ruby? I have some data that I need to > access as if it were an array, but I also need to insert/delete > items frequently. If I was using C, I'd just create a doubly > linked list. But I don't have a good idea of how to create one > in Ruby. irb(main):001:0> a = %w(The brown fox jumped the dog.) => ["The", "brown", "fox", "jumped", "the", "dog."] irb(main):002:0> a[1, 0] = "quick"; a => ["The", "quick", "brown", "fox", "jumped", "the", "dog."] irb(main):003:0> a[-1, 0] = "lazy"; a => ["The", "quick", "brown", "fox", "jumped", "the", "lazy", "dog."] irb(main):007:0> a[a.index("jumped") + 1, 0] = "over"; a => ["The", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog."] irb(main):008:0> You probably don't need a linked list for this; there are other things where a linked list or a circular linked list would be useful and necessary, but not this as such. -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca