Well, I'm trying insert a block into a series of blocks:
Consider the following code:
;===============================
triple: copy []
insert/only triple [1 234]
print mold triple
insert/only head triple [2 234]
print mold triple
insert/only next triple [3 345]
print mold triple
insert/only triple/2 [4 456] ; I've done this wrong
print mold triple
; == the results are:
[[1 234]]
[[2 234] [1 234]]
[[2 234] [3 345] [1 234]]
[[2 234] [[4 456] 3 345] [1 234]]
; what I'm really looking for at the last output line is:
[[2 234] [4 456] [3 345] [1 234]]
What should I do differently?
Thanks
-Tim

At 01:36 PM 7/3/00 -0700, you wrote:
>
>Well, as you know, you get doubly linked lists for free in REBOL.
>That's called a block.  To do the other part, I'd just make the items
>in your block another block or an object.  Then hold an index in one
>of the vars in that.
>
>triple: copy [] ; the linked list
>foreach item [[none 42] [4 9700] [1 15] [3 1846]] [
>       repend triple item
>]
>
>now there are four items in triple.  Each item is a block where the
>first number is what you call *mrk in your structure and the second
>number is the num you have in your struct.  The marker is an index
>back into triple so that you can do 'pick triple triple/2/1' and that
>will bring back the block indexed by the third link of the second item 
>in triple, namely item number four "[3 1846]".
>
>Another thing you could do is put an actual reference to triple into 
>the block:
>repend triple [skip triple 3 675]
>
>This way the first item in the block is actually a refernce into the
>triple block.
>
>You could do this with objects as well instead of blocks but I'll
>leave that excercise to the reader.  The implementation you choose
>should be the one best suited for your application.  Take into account
>all the uses of that third link, how much data you want to store in
>this item, and how you will be manipulating it.
>
>Sterling
>
>> Hello:
>>      I'd like to implement a *triple* linked list in rebol.
>> Below is a "c" structure: I'd welcome advice on how
>> to translate this to a rebol data structure.
>> If I'm correct, the nxt and prv elements are encapsulated
>> by a rebol list. What I'd like to figure out is how to
>> manually reference another node in the list.
>> (the mrk element)
>> 
>>   typedef struct test_node
>>   {
>>     struct test_node *nxt; // points to next node
>>     struct test_node *prv; // points to previous node
>>     struct test_node *mrk; // points to a randomly selected node
>>     long num;
>>   }TestNode;
>> 
>> Thanks In Advance
>> Regards
>> -Tim
>> 
>> 
>
>

Reply via email to