def link_(a, nodes, b)
      if nodes.empty?
        if a.nil?
          @first = b
        else
          a.instance_variable_set(:@next, b)
        end
        if b.nil?
          @last = a
        else
          b.instance_variable_set(:@prev, a)
        end
      else
        # connect `a' and `b'
        first = nodes.first
        if a.nil?
          @first = first
        else
          a.instance_variable_set(:@next, first)
        end
        last = nodes.last
        if b.nil?
          @last = last
        else
          b.instance_variable_set(:@prev, last)
        end

        # connect `nodes'
        if nodes.length == 1
          node = nodes[0]
          node.instance_variable_set(:@prev, a)
          node.instance_variable_set(:@next, b)
        else
          first.instance_variable_set(:@next, nodes[ 1])
          first.instance_variable_set(:@prev, a)
          last. instance_variable_set(:@prev, nodes[-2])
          last. instance_variable_set(:@next, b)
          (1...nodes.length-1).each do |i|
            n = nodes[i]
            n.instance_variable_set(:@prev, nodes[i-1])
            n.instance_variable_set(:@next, nodes[i+1])
          end
        end
      end
    end
def link_(a, nodes, b)
      if nodes.empty?
        if a.nil?
          @first = b
        else
          a.instance_variable_set(:@next, b)
        end
        if b.nil?
          @last = a
        else
          b.instance_variable_set(:@prev, a)
        end
      else
        # connect `a' and `b'
        first = nodes.first
        if a.nil?
          @first = first
        else
          a.instance_variable_set(:@next, first)
        end
        last = nodes.last
        if b.nil?
          @last = last
        else
          b.instance_variable_set(:@prev, last)
        end

        # connect `nodes'
        if nodes.length == 1
          node = nodes[0]
          node.instance_variable_set(:@prev, a)
          node.instance_variable_set(:@next, b)
        else
          first.instance_variable_set(:@next, nodes[ 1])
          first.instance_variable_set(:@prev, a)
          last. instance_variable_set(:@prev, nodes[-2])
          last. instance_variable_set(:@next, b)
          (1...nodes.length-1).each do |i|
            n = nodes[i]
            n.instance_variable_set(:@prev, nodes[i-1])
            n.instance_variable_set(:@next, nodes[i+1])
          end
        end
      end
    end
Link up `nodes' between `a' and `b'.