func (g *Graph) BFS(start int) { queue := []int{} queue = append(queue, start) visited := bitset.NewBitSet() for i := 0; i < len(queue); i++ { v := g.nodes[queue[i]] fmt.Printf("Visiting %d\n", v.Rank) // mark v as visited visited.Set(v.Rank) neighbors, _ := v.GetNeighbors() for _, neighbor := range neighbors { if !visited.IsSet(neighbor.Rank) { queue = append(queue, neighbor.Rank) } } } }
func (g *Graph) DoDFS(start int) { g.DFS(start, bitset.NewBitSet(), bitset.NewBitSet()) }