0
def breadth_first_search(adj_matrix, source_index, end_index)
node_queue = [source_index]
puts "#{source_index} stored into queue \n"
loop do
curr_node = node_queue.pop
puts "#{curr_node} popped \n"
return false if curr_node == nil
return true if curr_node == end_index
children = (0..adj_matrix.length-1).to_a.select do |i|
adj_matrix[curr_node][i] == 1
end
puts "children: #{children}"
node_queue = children + node_queue
puts "node_queue: #{node_queue}"
end
end
我可以理解它在概念上的作用,但實際的語法是我不明白的。孩子們是不是變量是一個用循環存儲元素的數組?子變量數組中的這段代碼是什麼意思?