From: Aredridel Date: 2005-04-05T04:46:53+09:00 Subject: Re: doubly linked list in Ruby? On Tue, 2005-04-05 at 03:39 +0900, 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. In Ruby, you have it easy: Variables themselves are pointers. If you have a class like so: class Node attr_accessor :up, :down, :string end then you can just assign a Node to up, a Node to down, and a String to string. That class is the equivalent of a C structure like so: struct node { struct node *up; struct node *down; char **string; } Though in C, you could get away with just char * for string. Ari