Class: CodeCook::DFS::Graph

Inherits:
Object
  • Object
show all
Defined in:
手写代码必备手册(Ruby版).rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Graph) initialize(size)

Returns a new instance of Graph



494
495
496
497
# File '手写代码必备手册(Ruby版).rb', line 494

def initialize(size)
    @size = size
    @adj  = Array.new(size) { Set.new }
end

Instance Attribute Details

- (Object) adj

Returns the value of attribute adj



492
493
494
# File '手写代码必备手册(Ruby版).rb', line 492

def adj
  @adj
end

- (Object) size

Returns the value of attribute size



492
493
494
# File '手写代码必备手册(Ruby版).rb', line 492

def size
  @size
end

Instance Method Details

- (Object) add_edge(v, w)



499
500
501
502
# File '手写代码必备手册(Ruby版).rb', line 499

def add_edge(v, w)
    @adj[v].add(w)
    @adj[w].add(v)
end